<?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 Issue with Python modules when attempting to execute app script. &amp;quot;ImportError: No module named searchcommands&amp;quot; in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Issue-with-Python-modules-when-attempting-to-execute-app-script/m-p/205578#M2741</link>
    <description>&lt;P&gt;I am trying to use an app that appears to call some Python scripts to get the data into Splunk. &lt;/P&gt;

&lt;P&gt;Splunk is having some trouble with the Python modules required to run the script, and I am not quite sure how to solve it using Splunk's own Python environment. (I could probably fix this if Splunk used a standalone Python environment, but I do not know how to get it to do that)&lt;/P&gt;

&lt;P&gt;Here is the log from the job inspector:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;09-21-2016 12:09:48.162 INFO  ChunkedExternProcessor - Running process: "C:\Program Files\Splunk\bin\python.exe" "C:\Program Files\Splunk\etc\apps\TA-prtg\bin\prtglivedata.py"
09-21-2016 12:09:48.340 ERROR ChunkedExternProcessor - EOF while attempting to read transport header
09-21-2016 12:09:48.342 ERROR ChunkedExternProcessor - Error in 'prtglivedata' command: External search command exited unexpectedly with non-zero error code 1.
09-21-2016 12:09:48.342 INFO  UserManager - Unwound user context: admin -&amp;gt; NULL
09-21-2016 12:09:48.345 ERROR ChunkedExternProcessor - stderr: Traceback (most recent call last):
09-21-2016 12:09:48.346 ERROR ChunkedExternProcessor - stderr:   File "C:\Program Files\Splunk\etc\apps\TA-prtg\bin\prtglivedata.py", line 32, in &amp;lt;module&amp;gt;
09-21-2016 12:09:48.346 ERROR ChunkedExternProcessor - stderr:     from splunklib.searchcommands import dispatch, GeneratingCommand, Configuration, Option, validators
09-21-2016 12:09:48.346 ERROR ChunkedExternProcessor - stderr: ImportError: No module named searchcommands
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I tried to run the Python script directly using Splunk's Python, but that throws an error as well:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;c:\Program Files\Splunk\bin&amp;gt;splunk cmd python "C:\Program Files\Splunk\etc\apps\TA-prtg\bin\prtglivedata.py"
Traceback (most recent call last):
  File "C:\Program Files\Splunk\etc\apps\TA-prtg\bin\prtglivedata.py", line 32, in &amp;lt;module&amp;gt;
    from splunklib.searchcommands import dispatch, GeneratingCommand, Configuration, Option, validators
ImportError: No module named searchcommands
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 21 Sep 2016 17:45:33 GMT</pubDate>
    <dc:creator>evan_roggenkamp</dc:creator>
    <dc:date>2016-09-21T17:45:33Z</dc:date>
    <item>
      <title>Issue with Python modules when attempting to execute app script. "ImportError: No module named searchcommands"</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Issue-with-Python-modules-when-attempting-to-execute-app-script/m-p/205578#M2741</link>
      <description>&lt;P&gt;I am trying to use an app that appears to call some Python scripts to get the data into Splunk. &lt;/P&gt;

&lt;P&gt;Splunk is having some trouble with the Python modules required to run the script, and I am not quite sure how to solve it using Splunk's own Python environment. (I could probably fix this if Splunk used a standalone Python environment, but I do not know how to get it to do that)&lt;/P&gt;

&lt;P&gt;Here is the log from the job inspector:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;09-21-2016 12:09:48.162 INFO  ChunkedExternProcessor - Running process: "C:\Program Files\Splunk\bin\python.exe" "C:\Program Files\Splunk\etc\apps\TA-prtg\bin\prtglivedata.py"
09-21-2016 12:09:48.340 ERROR ChunkedExternProcessor - EOF while attempting to read transport header
09-21-2016 12:09:48.342 ERROR ChunkedExternProcessor - Error in 'prtglivedata' command: External search command exited unexpectedly with non-zero error code 1.
09-21-2016 12:09:48.342 INFO  UserManager - Unwound user context: admin -&amp;gt; NULL
09-21-2016 12:09:48.345 ERROR ChunkedExternProcessor - stderr: Traceback (most recent call last):
09-21-2016 12:09:48.346 ERROR ChunkedExternProcessor - stderr:   File "C:\Program Files\Splunk\etc\apps\TA-prtg\bin\prtglivedata.py", line 32, in &amp;lt;module&amp;gt;
09-21-2016 12:09:48.346 ERROR ChunkedExternProcessor - stderr:     from splunklib.searchcommands import dispatch, GeneratingCommand, Configuration, Option, validators
09-21-2016 12:09:48.346 ERROR ChunkedExternProcessor - stderr: ImportError: No module named searchcommands
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I tried to run the Python script directly using Splunk's Python, but that throws an error as well:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;c:\Program Files\Splunk\bin&amp;gt;splunk cmd python "C:\Program Files\Splunk\etc\apps\TA-prtg\bin\prtglivedata.py"
Traceback (most recent call last):
  File "C:\Program Files\Splunk\etc\apps\TA-prtg\bin\prtglivedata.py", line 32, in &amp;lt;module&amp;gt;
    from splunklib.searchcommands import dispatch, GeneratingCommand, Configuration, Option, validators
ImportError: No module named searchcommands
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Sep 2016 17:45:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Issue-with-Python-modules-when-attempting-to-execute-app-script/m-p/205578#M2741</guid>
      <dc:creator>evan_roggenkamp</dc:creator>
      <dc:date>2016-09-21T17:45:33Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Python modules when attempting to execute app script. "ImportError: No module named searchcommands"</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Issue-with-Python-modules-when-attempting-to-execute-app-script/m-p/205579#M2742</link>
      <description>&lt;P&gt;We run standard python by calling python and the script we want in a bash script. Such as:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#!/bin/bash
/usr/bin/python /opt/splunk/bin/scripts/foo.py
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Though, this would be a .bat script for you, since looks like you are on Windows. You would also need to ensure the Windows server had a python install on it. By using the standard python install on your server, you can then add modules just like any other python system.&lt;/P&gt;

&lt;P&gt;Also, be aware, that running the script this way will require any paths you have in your py script to be absolute and not a relative reference.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Sep 2016 15:46:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Issue-with-Python-modules-when-attempting-to-execute-app-script/m-p/205579#M2742</guid>
      <dc:creator>richard_wilhite</dc:creator>
      <dc:date>2016-09-22T15:46:47Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Python modules when attempting to execute app script. "ImportError: No module named searchcommands"</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Issue-with-Python-modules-when-attempting-to-execute-app-script/m-p/205580#M2743</link>
      <description>&lt;P&gt;The app is somehow calling the python script in question.  I am not sure how I would tell this app to use a .bat file in place of trying to run:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; 09-21-2016 12:09:48.162 INFO  ChunkedExternProcessor - Running process: "C:\Program Files\Splunk\bin\python.exe" "C:\Program Files\Splunk\etc\apps\TA-prtg\bin\prtglivedata.py"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is there no other way to tell splunk to use regular non-splunk python?&lt;/P&gt;

&lt;P&gt;The other idea I had was creating some kind of wrapper where I copy and rename prtglivedata.py, and then use one copy to call the other with the correct environment, but this seems messy as well. &lt;/P&gt;</description>
      <pubDate>Thu, 22 Sep 2016 17:37:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Issue-with-Python-modules-when-attempting-to-execute-app-script/m-p/205580#M2743</guid>
      <dc:creator>evan_roggenkamp</dc:creator>
      <dc:date>2016-09-22T17:37:55Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Python modules when attempting to execute app script. "ImportError: No module named searchcommands"</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Issue-with-Python-modules-when-attempting-to-execute-app-script/m-p/205581#M2744</link>
      <description>&lt;P&gt;Someone else may be better suited to answer this question than I. However, I hate to leave you hanging. Looking at your output, above, more closely, I see the ImportError is for searchcommands. Which is part of the Splunk SDK, I believe. I would assume the necessary SDK modules would be built into the app. But maybe that is the next thing to look at.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Sep 2016 20:07:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Issue-with-Python-modules-when-attempting-to-execute-app-script/m-p/205581#M2744</guid>
      <dc:creator>richard_wilhite</dc:creator>
      <dc:date>2016-09-23T20:07:57Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Python modules when attempting to execute app script. "ImportError: No module named searchcommands"</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Issue-with-Python-modules-when-attempting-to-execute-app-script/m-p/205582#M2745</link>
      <description>&lt;P&gt;A related thread about the error - &lt;CODE&gt;ERROR ChunkedExternProcessor - stderr: ImportError: No module named searchcommands&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;At &lt;A href="https://answers.splunk.com/answers/431903/why-am-i-getting-error-no-module-named-splunklibse.html"&gt;Why am I getting error "No module named splunklib.searchcommands" trying to run a custom search command?&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Sep 2016 23:56:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Issue-with-Python-modules-when-attempting-to-execute-app-script/m-p/205582#M2745</guid>
      <dc:creator>ddrillic</dc:creator>
      <dc:date>2016-09-24T23:56:49Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Python modules when attempting to execute app script. "ImportError: No module named searchcommands"</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Issue-with-Python-modules-when-attempting-to-execute-app-script/m-p/205583#M2746</link>
      <description>&lt;P&gt;You'll need to place the splunk-sdk python library in {{SPLUNK_HOME}}/lib/python-2.7/site-packages or locally in {{SPLUNK_HOME}}/etc/apps/TA-prtg/bin. Download it from here: &lt;A href="http://dev.splunk.com/python" target="_blank"&gt;http://dev.splunk.com/python&lt;/A&gt;. You should then be able to import packages from splunklib in the default Splunk python interpreter.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 11:06:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Issue-with-Python-modules-when-attempting-to-execute-app-script/m-p/205583#M2746</guid>
      <dc:creator>adambloom</dc:creator>
      <dc:date>2020-09-29T11:06:02Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Python modules when attempting to execute app script. "ImportError: No module named searchcommands"</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Issue-with-Python-modules-when-attempting-to-execute-app-script/m-p/205584#M2747</link>
      <description>&lt;P&gt;I think we are on the right track with that thought. &lt;BR /&gt;
Thanks Richard &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2016 13:24:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Issue-with-Python-modules-when-attempting-to-execute-app-script/m-p/205584#M2747</guid>
      <dc:creator>evan_roggenkamp</dc:creator>
      <dc:date>2016-09-26T13:24:13Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Python modules when attempting to execute app script. "ImportError: No module named searchcommands"</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Issue-with-Python-modules-when-attempting-to-execute-app-script/m-p/205585#M2748</link>
      <description>&lt;P&gt;evan - see my comment above. Somehow ended up above this and not below.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2016 15:10:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Issue-with-Python-modules-when-attempting-to-execute-app-script/m-p/205585#M2748</guid>
      <dc:creator>adambloom</dc:creator>
      <dc:date>2016-09-26T15:10:20Z</dc:date>
    </item>
  </channel>
</rss>

