All Apps and Add-ons

How do I use numpy in a custom search command?

Explorer

I have installed the Python for Scientific Computing App into Splunk Enterprise. It seems to have installed correctly, as I can make use of the ML toolkit.

I was expecting to be able to use numpy in my custom search commands outside of the ML toolkit App as well, but this is not the case. In custom search commands numpy cannot be imported ( ImportError: No module named numpy).

How can I enable numpy/the Scientific Computing App in other apps or, alternatively, how can I install numpy there?

0 Karma
1 Solution

Explorer

What worked for me was copying the exec_anconda.py file included with the Python for Scientific Computing Addon into the folder of my app and than, as instructed, add

import exec_anaconda
exec_anaconda.exec_anaconda()
import numpy as np
import pandas as pd

at the top of my python file.

I than hit the ImportError: No module named ssl Error, which I could fix with this patch for the python sdk (which nowadays needs to be trivially adapted to the latest version of the SDK).

View solution in original post

0 Karma

Explorer

What worked for me was copying the exec_anconda.py file included with the Python for Scientific Computing Addon into the folder of my app and than, as instructed, add

import exec_anaconda
exec_anaconda.exec_anaconda()
import numpy as np
import pandas as pd

at the top of my python file.

I than hit the ImportError: No module named ssl Error, which I could fix with this patch for the python sdk (which nowadays needs to be trivially adapted to the latest version of the SDK).

View solution in original post

0 Karma

SplunkTrust
SplunkTrust

@geier If your problem is resolved, please accept an answer to help future readers.

---
If this reply helps you, an upvote would be appreciated.
0 Karma

Engager

@geier Could you please explain more widely how to solve the problem with " ImportError: No module named ssl Error"

0 Karma

Explorer

I can't actually see my own links here (perhaps they are not shown because I don't have the necessary karma?). The patch I was talking about is this one:

https://answers.splunk.com/answers/474207/python-for-scientific-computing-and-the-sdk.html#comment-6...

0 Karma

Motivator

Copy your required packages/files from /usr/local/lib/python2.7/dist-packages to /opt/splunk/lib/python2.7/site-packages/

0 Karma

Builder

Numpy is not included in Splunk internal python, but you can either call an external python with numpy or build an egg which includes numpy.

See the following answer:
https://answers.splunk.com/answers/484021/help-in-import-of-numpy-in-splunk.html#answer-483810

0 Karma