<?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 Script Not working via search command in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Python-Script-Not-working-via-search-command/m-p/153973#M43263</link>
    <description>&lt;P&gt;Splunk 6.1.x seems to have a problem executing custom commands (e.g. python scripts) which are using relative paths for example to access a file inside of app directory.&lt;/P&gt;

&lt;P&gt;In earlier versions (6.0.x) the script was started with current directory pointing to the app/bin directory, in 6.1.2 we faced a problem that the current dírectory is now a temporary search directory.&lt;/P&gt;

&lt;P&gt;To do a workaround we had to put:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;os.chdir(os.path.dirname(__file__))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;at the beginning of every python script. Maybe it is similar problem at your side.&lt;/P&gt;

&lt;P&gt;Edit: if you are using Linux: there is a linux own Python installation, splunk uses it own. So if you have a lib inside your linux installation it is not automatically available inside of splunk-python scripts.&lt;/P&gt;</description>
    <pubDate>Wed, 23 Jul 2014 13:05:23 GMT</pubDate>
    <dc:creator>psobisch</dc:creator>
    <dc:date>2014-07-23T13:05:23Z</dc:date>
    <item>
      <title>Python Script Not working via search command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Python-Script-Not-working-via-search-command/m-p/153972#M43262</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have written a python script which runs perfectly when opened directly, but when i run it via search &lt;CODE&gt;|script python prediction&lt;/CODE&gt; then it returns error code 1.&lt;/P&gt;

&lt;P&gt;While more deep debugging i found that i am using below R library at which the code doesn't  works and gives me error. When i comment the below line, the script works until it reaches the dependency of the below library.&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;from rpy2.robjects.packages&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;Now point is since this python script works perfectly when run from that same app folder, so python is able to have access to the rpy2, but when i run it via Splunk search it is not able to reach to rpy2 library.&lt;/P&gt;

&lt;P&gt;Can any one help me how do make it run? Is there any specific steps to be taken to install rpy2 so python for splunk?&lt;/P&gt;

&lt;P&gt;Also i had copied rpy2 folder in the bin directory of the app, but still it didnt worked via search.&lt;/P&gt;

&lt;P&gt;Can anyone please help me any workaround to make this script run via splunk search&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jul 2014 12:44:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Python-Script-Not-working-via-search-command/m-p/153972#M43262</guid>
      <dc:creator>harshal_chakran</dc:creator>
      <dc:date>2014-07-23T12:44:58Z</dc:date>
    </item>
    <item>
      <title>Re: Python Script Not working via search command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Python-Script-Not-working-via-search-command/m-p/153973#M43263</link>
      <description>&lt;P&gt;Splunk 6.1.x seems to have a problem executing custom commands (e.g. python scripts) which are using relative paths for example to access a file inside of app directory.&lt;/P&gt;

&lt;P&gt;In earlier versions (6.0.x) the script was started with current directory pointing to the app/bin directory, in 6.1.2 we faced a problem that the current dírectory is now a temporary search directory.&lt;/P&gt;

&lt;P&gt;To do a workaround we had to put:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;os.chdir(os.path.dirname(__file__))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;at the beginning of every python script. Maybe it is similar problem at your side.&lt;/P&gt;

&lt;P&gt;Edit: if you are using Linux: there is a linux own Python installation, splunk uses it own. So if you have a lib inside your linux installation it is not automatically available inside of splunk-python scripts.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jul 2014 13:05:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Python-Script-Not-working-via-search-command/m-p/153973#M43263</guid>
      <dc:creator>psobisch</dc:creator>
      <dc:date>2014-07-23T13:05:23Z</dc:date>
    </item>
    <item>
      <title>Re: Python Script Not working via search command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Python-Script-Not-working-via-search-command/m-p/153974#M43264</link>
      <description>&lt;P&gt;I tried running the same code in Splunk 6.0, but it didnt worked yet! Also i tried your solution in both 6.0 &amp;amp; 6.1 but it didn't helped.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jul 2014 12:02:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Python-Script-Not-working-via-search-command/m-p/153974#M43264</guid>
      <dc:creator>harshal_chakran</dc:creator>
      <dc:date>2014-07-24T12:02:05Z</dc:date>
    </item>
  </channel>
</rss>

