All Apps and Add-ons

Issue with python module when executing python script form splunk

ygkr
New Member

alt text

Here is the snapshot of the issue which I can c from job inspector and my below script is working fine in python environment but not in splunk

**import random
import sys

import scipy as sc

import scipy.stats as sct
x = sys.argv1
def ran_w():

z= []
k= []
for i in range(0,int(x)):
    z =random.random()
    k =sct.norm.ppf

(z,loc=197.265217391304,scale=33.1340303880203)
print("Random Number")
print(z)
print("IND Value")
print(k)

ran_w()**

Kindly help me... and thanks in advance..

Tags (1)
0 Karma

jkat54
SplunkTrust
SplunkTrust

It's telling you it can't find the stats module in the scypi library in your splunk_home/etc/apps/search/bin directory. Put it there and the error will go away.

jkat54
SplunkTrust
SplunkTrust

Consider this image of a app/bin directory that I have for an Azure - Splunk integration:

tableService.py imports dateutil and azure. These libraries are not packaged with Splunk's python. So i have to put them here in the bin directory in order to use "import dateutil" in my python script tableService.py.

alt text

0 Karma

ygkr
New Member

jkat54 thanks for the response and will u plz elobrate on putting the module into splunk bin directory as of now I saved my python script in bin and running it from search bar but I can c my output for the script in Anaconda IDE... I m new to python thats y m asking u to eloborate... the things like where to download the package and how to install that in bin folder of splunk....

0 Karma

sideview
SplunkTrust
SplunkTrust

One piece maybe you're missing is instead of testing the script just with "python script.py", you use "splunk cmd python script.py" This causes splunk to do a couple important things that end up mirroring how Splunk will run your script later. One of these things is putting $SPLUNK_HOME/bin in pythonpath so it can see the files you're trying to import.

0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...