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!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...