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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

ATTENTION: We’re Moving! (AGAIN!)

The Splunk Community Slack is undergoing a system migration to keep our workspace secure and ...

Deep Dive: Optimizing Telemetry Pipelines in Splunk Observability Cloud

In this session, we will peel back the layers of Splunk Observability Cloud’s cost-optimization features. ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...