<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python scripted inputs run with the wrong version of Python in Splunk 4.1.2 in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Python-scripted-inputs-run-with-the-wrong-version-of-Python-in/m-p/14057#M53</link>
    <description>&lt;P&gt;Splunk't bundled version of python is always used for python scripts.&lt;/P&gt;

&lt;P&gt;This is like the different between running &lt;CODE&gt;./applicationFatalTraps.py&lt;/CODE&gt; vs running &lt;CODE&gt;python applicationFatalTraps.py&lt;/CODE&gt;.  With the first, the kernel decides because of that first &lt;CODE&gt;!#&lt;/CODE&gt; line, where as with the second, it depends on which &lt;CODE&gt;python&lt;/CODE&gt; first occurs in your path.  And in the case of splunk, their own &lt;CODE&gt;python&lt;/CODE&gt; is always first.  (This may not be 100% technically accurate, but I think it gives you the right idea.)&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;To use a different python interpreter, simply create small shell script:&lt;/P&gt;

&lt;P&gt;Example &lt;CODE&gt;/foo/bar/scripts/applicationFatalTraps.sh&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; #!/bin/sh
 unset PYTHONPATH
 unset LD_LIBRARY_PATH
 exec /usr/bin/python /foo/bar/scripts/applicationFatalTraps.py
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or, if you need a more platform independent solution, you can use a small python script to launch a different interpreter.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import os, sys
# Remove problematic environmental variables if they exist.
for envvar in ("PYTHONPATH", "LD_LIBRARY_PATH"):
    if envvar in os.environ:
        del os.environ[envvar]

python_executable = "/usr/bin/python"
real_script = "/opt/splunk/etc/apps/myapp/bin/applicationFatalTraps.py"

os.execv(python_executable, [ python_executable, real_script ] + sys.argv[1:])
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;EM&gt;This was copied from &lt;A href="http://answers.splunk.com/questions/585/external-lookup-command-in-windows/590#590" rel="nofollow"&gt;jrodman's post&lt;/A&gt;.  Since it was so short I figured I'd just copy it here.&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;Update:&lt;/EM&gt;   Just another thought.  What happens if you simply rename &lt;CODE&gt;ApplicationFatalTraps.py&lt;/CODE&gt; to &lt;CODE&gt;ApplicationFatalTraps&lt;/CODE&gt; (no extension).  It's possible that splunk will, in that case issue an OS level system execution call and therefore let the OS decide which interpreter to run.  You might still run into trouble because of some environmental variables, such as &lt;CODE&gt;$PYTHONPATH&lt;/CODE&gt;... That thought just occurred to me.  But I haven't tried, so who knows.&lt;/P&gt;</description>
    <pubDate>Fri, 21 May 2010 23:49:38 GMT</pubDate>
    <dc:creator>Lowell</dc:creator>
    <dc:date>2010-05-21T23:49:38Z</dc:date>
    <item>
      <title>Python scripted inputs run with the wrong version of Python in Splunk 4.1.2</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Python-scripted-inputs-run-with-the-wrong-version-of-Python-in/m-p/14056#M52</link>
      <description>&lt;P&gt;We are running a few Python scripts as Splunk scripted inputs. This is an example stanza from our inputs.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[script:///foo/bar/scripts/applicationFatalTraps.py]
interval = 60
index = main
sourcetype = log4j
source = script:applicationFatalTraps
disabled = 0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The first line of the script specifies which Python to run:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#!/usr/bin/python
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When run from the Linux command line, the script logs this expected version of Python, which is installed as /usr/bin/python:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Python 2.3.4 (#1, Feb 18 2008, 17:16:53)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-9)] on linux2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, when run as scripted input from Splunk 4.1.2, the script logs this newer version of Python :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Python version = "2.6.4 (r264:75706, Apr  8 2010, 00:28:45) 
[GCC 3.4.6 20060404 (Red Hat 3.4.6-3)]"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Needless to say, the Python version difference breaks something in the script.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Question:&lt;/STRONG&gt; Why is Splunk running the script with the wrong version of Python?&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2010 23:32:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Python-scripted-inputs-run-with-the-wrong-version-of-Python-in/m-p/14056#M52</guid>
      <dc:creator>joelshprentz</dc:creator>
      <dc:date>2010-05-21T23:32:13Z</dc:date>
    </item>
    <item>
      <title>Re: Python scripted inputs run with the wrong version of Python in Splunk 4.1.2</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Python-scripted-inputs-run-with-the-wrong-version-of-Python-in/m-p/14057#M53</link>
      <description>&lt;P&gt;Splunk't bundled version of python is always used for python scripts.&lt;/P&gt;

&lt;P&gt;This is like the different between running &lt;CODE&gt;./applicationFatalTraps.py&lt;/CODE&gt; vs running &lt;CODE&gt;python applicationFatalTraps.py&lt;/CODE&gt;.  With the first, the kernel decides because of that first &lt;CODE&gt;!#&lt;/CODE&gt; line, where as with the second, it depends on which &lt;CODE&gt;python&lt;/CODE&gt; first occurs in your path.  And in the case of splunk, their own &lt;CODE&gt;python&lt;/CODE&gt; is always first.  (This may not be 100% technically accurate, but I think it gives you the right idea.)&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;To use a different python interpreter, simply create small shell script:&lt;/P&gt;

&lt;P&gt;Example &lt;CODE&gt;/foo/bar/scripts/applicationFatalTraps.sh&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; #!/bin/sh
 unset PYTHONPATH
 unset LD_LIBRARY_PATH
 exec /usr/bin/python /foo/bar/scripts/applicationFatalTraps.py
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or, if you need a more platform independent solution, you can use a small python script to launch a different interpreter.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import os, sys
# Remove problematic environmental variables if they exist.
for envvar in ("PYTHONPATH", "LD_LIBRARY_PATH"):
    if envvar in os.environ:
        del os.environ[envvar]

python_executable = "/usr/bin/python"
real_script = "/opt/splunk/etc/apps/myapp/bin/applicationFatalTraps.py"

os.execv(python_executable, [ python_executable, real_script ] + sys.argv[1:])
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;EM&gt;This was copied from &lt;A href="http://answers.splunk.com/questions/585/external-lookup-command-in-windows/590#590" rel="nofollow"&gt;jrodman's post&lt;/A&gt;.  Since it was so short I figured I'd just copy it here.&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;Update:&lt;/EM&gt;   Just another thought.  What happens if you simply rename &lt;CODE&gt;ApplicationFatalTraps.py&lt;/CODE&gt; to &lt;CODE&gt;ApplicationFatalTraps&lt;/CODE&gt; (no extension).  It's possible that splunk will, in that case issue an OS level system execution call and therefore let the OS decide which interpreter to run.  You might still run into trouble because of some environmental variables, such as &lt;CODE&gt;$PYTHONPATH&lt;/CODE&gt;... That thought just occurred to me.  But I haven't tried, so who knows.&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2010 23:49:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Python-scripted-inputs-run-with-the-wrong-version-of-Python-in/m-p/14057#M53</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2010-05-21T23:49:38Z</dc:date>
    </item>
    <item>
      <title>Re: Python scripted inputs run with the wrong version of Python in Splunk 4.1.2</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Python-scripted-inputs-run-with-the-wrong-version-of-Python-in/m-p/14058#M54</link>
      <description>&lt;P&gt;Thanks, Lowell.&lt;/P&gt;

&lt;P&gt;We reviewed your excellent response and decided to upgrade our Python script to run with Python 2.6, the version currently used by Splunk.&lt;/P&gt;

&lt;P&gt;May I recommend that you update the documentation to reveal Splunk's special handling of Python scripts?&lt;/P&gt;</description>
      <pubDate>Thu, 27 May 2010 03:13:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Python-scripted-inputs-run-with-the-wrong-version-of-Python-in/m-p/14058#M54</guid>
      <dc:creator>joelshprentz</dc:creator>
      <dc:date>2010-05-27T03:13:41Z</dc:date>
    </item>
    <item>
      <title>Re: Python scripted inputs run with the wrong version of Python in Splunk 4.1.2</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Python-scripted-inputs-run-with-the-wrong-version-of-Python-in/m-p/14059#M55</link>
      <description>&lt;P&gt;Did you upgrade your local python install, or are you just using splunk's bundled python distro.... it wasn't clear from your comment...   BTW, I don't have access to update the docs.  However, you could simply email &lt;A href="mailto:docs@splunk.com"&gt;docs@splunk.com&lt;/A&gt; with your request and add a link to this page.  The docs team has been very responsive to all my nagging about various little doc issues here and there.  &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 May 2010 04:01:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Python-scripted-inputs-run-with-the-wrong-version-of-Python-in/m-p/14059#M55</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2010-05-27T04:01:13Z</dc:date>
    </item>
    <item>
      <title>Re: Python scripted inputs run with the wrong version of Python in Splunk 4.1.2</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Python-scripted-inputs-run-with-the-wrong-version-of-Python-in/m-p/14060#M56</link>
      <description>&lt;P&gt;Hint: to get at Splunk's version of python, run the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$SPLUNK_HOME/bin/splunk cmd python
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So, to test a script in it,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$SPLUNK_HOME/bin/splunk cmd python yourscript.py
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Sep 2010 03:11:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Python-scripted-inputs-run-with-the-wrong-version-of-Python-in/m-p/14060#M56</guid>
      <dc:creator>Jason</dc:creator>
      <dc:date>2010-09-14T03:11:51Z</dc:date>
    </item>
    <item>
      <title>Re: Python scripted inputs run with the wrong version of Python in Splunk 4.1.2</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Python-scripted-inputs-run-with-the-wrong-version-of-Python-in/m-p/14061#M57</link>
      <description>&lt;P&gt;FWIW, in both recipes you probably want to consider manipulating the PATH variable as well, to put the things you'll want to use higher on the path than splunk's bin (or dropping the splunk bin dir entirely if that matches your goals), but that's harder to encapsulate in an example.&lt;/P&gt;</description>
      <pubDate>Wed, 13 May 2015 21:24:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Python-scripted-inputs-run-with-the-wrong-version-of-Python-in/m-p/14061#M57</guid>
      <dc:creator>jrodman</dc:creator>
      <dc:date>2015-05-13T21:24:16Z</dc:date>
    </item>
  </channel>
</rss>

