All Apps and Add-ons

Why do I keep getting errors when trying to import Pandas with Splunk's python?

ohms
New Member

I am trying to import Pandas in a Splunk app that I am developing. The app also contains fpdf to create a pdf and insert the images that are produced using Pandas.  2 of the 3 solutions that I tried produce an error as soon as I put 'import pandas'.

1. Solution 1: importing the Pandas module from a copy of the module that is located in the App's bin directory.

The error log says:

File "../splunk/etc/apps/<Appname>/bin/pandas/__init__.py", line 37, in <module>
f"C extension: {module} not built. If you want to import "
ImportError: C extension: No module named 'pandas._libs.tslibs.conversion' not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to build the C extensions first.

2. Solution 2: Just import the splunk lib from Splunk's Python (simply by putting 'import pandas' at the top of the code).

The error log says:

Traceback (most recent call last):
File "/splunk/etc/apps/<Appname>/bin/program.py", line 22, in <module>
import pandas
File "/splunk/lib/python3.7/site-packages/pandas/__init__.py", line 22, in <module>
from pandas.compat import (
File "/splunk/lib/python3.7/site-packages/pandas/compat/__init__.py", line 14, in <module>
from pandas._typing import F
File "/splunk/lib/python3.7/site-packages/pandas/_typing.py", line 12, in <module>
from mmap import mmap
ModuleNotFoundError: No module named 'mmap'

For the third and final attempt to make it work, I tried using a solution that I found in Splunk's forum, which is by using the app "Python for Scientific Computing". The steps that I have applied were:

1. Coping exec_anaconda.py to my app's bin.

2. Putting the following code at the very top of my script:

#!/usr/bin/python
import exec_anaconda
exec_anaconda.exec_anaconda()
# Put the rest of your imports below, e.g.:
import numpy as np

import pandas

What happens with this solution is that I get no more error on the 'import pandas', but I get errors from most of the other modules that I am working with (fpdf, pip and so on).

Does anybody know how to import pandas without getting these kind of errors?

Thank you very much.

Labels (1)
Tags (3)
0 Karma

damode1
Path Finder

Were you able to fix this error about no module found 'mmap'

If yes, please share solution. Thanks.

0 Karma
Get Updates on the Splunk Community!

Prove Your Splunk Prowess at .conf25—No Prereqs Required!

Your Next Big Security Credential: No Prerequisites Needed We know you’ve got the skills, and now, earning the ...

Splunk Observability Cloud's AI Assistant in Action Series: Observability as Code

This is the sixth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how to ...

Splunk Answers Content Calendar, July Edition I

Hello Community! Welcome to another month of Community Content Calendar series! For the month of July, we will ...