Splunk Dev

ImportError: No module named Site

po1splunk
New Member

I am trying out Splunk on Windows Server 2012, version 6.6.3 and attempting to do a scripted lookup with a python script. My actual script (makes HTTP call, returns json, I parse and return csv) works with my own installation of Python 2.7 but when I try to run it with the built-in Splunk version I get ImportError: No module named Site

I've searched and found a couple similar posts about this but what has me scratching my head is if I run "C:\Program Files\Splunk\bin\python.exe" test.py I get

ImportError: No module named Site 

Now, the only thing in test.py is the statement

print "hello"

If I run "C:\Program Files\Splunk\bin\python.exe" -S test.py I get the expected output

hello

This is a sanity test script of course, just to see if I can get it to do anything I'd expect. So what is going on with the -S (where I'm telling python to ignore site-packages I believe) vrs. not having that arg and I get an error?

Is there something wrong with my install? With a simple print statement I'd expect the built-in Python to work without issue but it does not.

Any ideas?? Thanks in advance for any input on this.

0 Karma
1 Solution

nickhills
Ultra Champion

If you want to run your script the way Splunk does (with its own libraries and modules) try this:

C:\Program Files\Splunk\bin\splunk cmd python ../path to/your script.py

I'm not suggesting this will solve your issue immediately, but under the covers that is how Splunk will execute your script.

If my comment helps, please give it a thumbs up!

View solution in original post

nickhills
Ultra Champion

If you want to run your script the way Splunk does (with its own libraries and modules) try this:

C:\Program Files\Splunk\bin\splunk cmd python ../path to/your script.py

I'm not suggesting this will solve your issue immediately, but under the covers that is how Splunk will execute your script.

If my comment helps, please give it a thumbs up!

po1splunk
New Member

Ah, subtle difference. This runs the script as intended. Thank you for this help!!

0 Karma
Get Updates on the Splunk Community!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...