All Apps and Add-ons

How do I use numpy in a custom search command?

geier
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

geier
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

geier
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).

0 Karma

BernardEAI
Communicator

Thanks for these pointers. I managed to get all the way to 

exec_anaconda.exec_anaconda()
 
running without errors (had to add the "/bin/util" folder of Splunk MLTK on my app bin path as per this post , and modify binding.py as per this post )
 
However, if I now import any libraries that are in the Python for Scientific Computing Addon (like numpy and pandas), I get an error.
0 Karma

richgalloway
SplunkTrust
SplunkTrust

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

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

nailkh
Engager

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

0 Karma

geier
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

splunker12er
Motivator

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

0 Karma

Azeemering
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
Get Updates on the Splunk Community!

The Payment Operations Wake-Up Call: Why Financial Institutions Can't Afford ...

The same scenario plays out across financial institutions daily. A payment system fails at 11:30 AM on a busy ...

Make Your Case: A Ready-to-Send Letter for Getting Approval to Attend .conf25

Hello Splunkers, Want to attend .conf25 in Boston this year but not sure how to convince your manager? We've ...

Community Spotlight: A Splunk Expert's Journey

In the world of data analytics, some journeys leave a lasting impact not only on the individual but on the ...