Archive

My own Python script cannot import Splunk Python library modules?

Path Finder

My own Python script cannot import Splunk Python library modules?

[root@localhost bin]# ./qqip.py 8.8.8.8
Traceback (most recent call last):
File "./qqip.py", line 162, in
import splunk.Intersplunk as si
ImportError: No module named splunk.Intersplunk

[root@localhost bin]# vim qqip.py

161 import re
162 import splunk.Intersplunk as si
163 ipre = re.compile("\d+.\d+.\d+.\d+")
164 results = []
165 if name == 'main':

[root@localhost bin]# find / -name Intersplunk
/opt/splunk/lib/python2.7/site-packages/splunk/Intersplunk.pyo
/opt/splunk/lib/python2.7/site-packages/splunk/Intersplunk.pyc
/opt/splunk/lib/python2.7/site-packages/splunk/Intersplunk.py

???

1 Solution

Legend

Splunk comes bundled with its own Python environment. You could either set your PYTHONPATH in order to make use of the packages available in it, or better yet you should run Splunk's python completely: /opt/splunk/bin/splunk cmd python <yourfile.py>.

View solution in original post

Explorer

Hello, I was the same problem with Mysql module that I was install on my Centos server

Splunk didn't work with this library, because splunk has they own python library...then you can fix it only added on the begin your script all libraries of python and also you must to add the python Centos library too... as this way

Find python packages

[root@xxxx]#find / -name site-packages
/usr/lib/python2.7/site-packages
/usr/lib64/python2.7/site-packages
/opt/splunk/etc/apps/SplunkSAScientificPythonlinuxx8664/bin/linuxx8664/lib/python2.7/site-packages
/opt/splunk/lib/python2.7/site-packages

Find python binary

[root@xxxx]# whereis python
python: /usr/bin/python2.7 /usr/bin/python /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7 /opt/splunk/bin/python /opt/splunk/bin/python2.7 /usr/share/man/man1/python.1.gz

include all at begin your script

import sys
sys.path.append('/usr/bin/python2.7')
sys.path.append('/usr/lib/python2.7/site-packages')
sys.path.append('/usr/lib64/python2.7/site-packages')

And that's it , you can run mysql module without any problem and create your alerts with this module.

Mysql Connection

import mysql.connector

I hope that this fix will help you
Joel Urtubia Ugarte

0 Karma

Legend

Splunk comes bundled with its own Python environment. You could either set your PYTHONPATH in order to make use of the packages available in it, or better yet you should run Splunk's python completely: /opt/splunk/bin/splunk cmd python <yourfile.py>.

View solution in original post

Path Finder

Ayn ,Thank you very much!

0 Karma