<?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: Scripted Input - Python Module Error in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Scripted-Input-Python-Module-Error/m-p/455349#M78779</link>
    <description>&lt;P&gt;Creating a wrapper to call a Python installation on the host has been the conventional Splunk wisdom for years, as was bundling needed modules into the app. Both these approaches have numerous problems though. Using the wrapper is typically temperamental to permissions, environment variables, and in the case of the default system Python possibly versions of Python even older than 2.7.&lt;/P&gt;

&lt;P&gt;My suggestion is to check out a new app I've written called &lt;A href="https://splunkbase.splunk.com/app/4322/"&gt;PyDen&lt;/A&gt; which allows you to create Python virtual environments and install PyPI packages to the environment. You can then use these environments to execute custom commands and scripted inputs.&lt;/P&gt;

&lt;P&gt;This provides three key advantages:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;You can pick the version of Python you'd like to write in, including 3.5 to 3.7&lt;/LI&gt;
&lt;LI&gt;Create an isolated environment that won't interfere with imports in other apps (this can happen when packages are bundled into apps)&lt;/LI&gt;
&lt;LI&gt;Install any package available on PyPI to the environment&lt;/LI&gt;
&lt;/OL&gt;</description>
    <pubDate>Tue, 26 Feb 2019 05:46:35 GMT</pubDate>
    <dc:creator>badarsebard</dc:creator>
    <dc:date>2019-02-26T05:46:35Z</dc:date>
    <item>
      <title>Scripted Input - Python Module Error</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Scripted-Input-Python-Module-Error/m-p/455345#M78775</link>
      <description>&lt;P&gt;I have a python script that pulls data from an SFTP source and writes the data to a file (&lt;STRONG&gt;myScript.py&lt;/STRONG&gt;). The script imports two modules that I installed. As such, I wrote a bash wrapper script to call my script and run it with standard python (&lt;STRONG&gt;myScriptLauncher.sh&lt;/STRONG&gt;).&lt;/P&gt;

&lt;P&gt;I can run the bash script from the command line fine. However, when I try to run it using Splunk (&lt;STRONG&gt;./splunk cmd /opt/splunk/etc/apps/myApp/bin/myScriptLauncher.sh&lt;/STRONG&gt;), I get a module import error. &lt;/P&gt;

&lt;P&gt;I'm not sure what I am doing wrong. Anyone have any suggestions?&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;error&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Traceback (most recent call last):
  File "./myScript.py", line 4, in &amp;lt;module&amp;gt;
    import pysftp
ImportError: No module named pysftp
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;myScript.py&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#!/usr/bin/env python

import json
import pysftp
import openpyxl

REST OF CODE GOES HERE
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;myScriptLauncher.sh&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#!/bin/bash

echo myScript is starting &amp;gt;&amp;amp;2

cd $( dirname "${BASH_SOURCE[0]}" )

exec /usr/bin/python ./myScript.py
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Feb 2019 02:27:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Scripted-Input-Python-Module-Error/m-p/455345#M78775</guid>
      <dc:creator>nakiamatthews</dc:creator>
      <dc:date>2019-02-07T02:27:27Z</dc:date>
    </item>
    <item>
      <title>Re: Scripted Input - Python Module Error</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Scripted-Input-Python-Module-Error/m-p/455346#M78776</link>
      <description>&lt;P&gt;@nakiamatthews &lt;/P&gt;

&lt;P&gt;I think you have installed&lt;CODE&gt;pysftp&lt;/CODE&gt; files in local python. So you should add path in your &lt;CODE&gt;myScript.py&lt;/CODE&gt; script OR you have to copy those file into splunk lib. &lt;/P&gt;

&lt;P&gt;See below ref link for your more info:&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/222934/modular-input-that-need-additional-python-modules.html"&gt;https://answers.splunk.com/answers/222934/modular-input-that-need-additional-python-modules.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/220196/import-non-native-python-libraries-into-splunk.html#answer-222585"&gt;https://answers.splunk.com/answers/220196/import-non-native-python-libraries-into-splunk.html#answer-222585&lt;/A&gt;&lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/8/can-i-add-python-modules-to-the-splunk-environment.html"&gt;https://answers.splunk.com/answers/8/can-i-add-python-modules-to-the-splunk-environment.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Feb 2019 05:48:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Scripted-Input-Python-Module-Error/m-p/455346#M78776</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-02-07T05:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: Scripted Input - Python Module Error</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Scripted-Input-Python-Module-Error/m-p/455347#M78777</link>
      <description>&lt;P&gt;I was under the impression that adding the modules to the splunk lib was not future proof - i.e. it will break whenever you upgrade Splunk.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Feb 2019 17:45:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Scripted-Input-Python-Module-Error/m-p/455347#M78777</guid>
      <dc:creator>nakiamatthews</dc:creator>
      <dc:date>2019-02-07T17:45:27Z</dc:date>
    </item>
    <item>
      <title>Re: Scripted Input - Python Module Error</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Scripted-Input-Python-Module-Error/m-p/455348#M78778</link>
      <description>&lt;P&gt;Also, I thought the point of the wrapper script was to call the .py script using standard python?&lt;/P&gt;</description>
      <pubDate>Thu, 07 Feb 2019 18:12:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Scripted-Input-Python-Module-Error/m-p/455348#M78778</guid>
      <dc:creator>nakiamatthews</dc:creator>
      <dc:date>2019-02-07T18:12:31Z</dc:date>
    </item>
    <item>
      <title>Re: Scripted Input - Python Module Error</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Scripted-Input-Python-Module-Error/m-p/455349#M78779</link>
      <description>&lt;P&gt;Creating a wrapper to call a Python installation on the host has been the conventional Splunk wisdom for years, as was bundling needed modules into the app. Both these approaches have numerous problems though. Using the wrapper is typically temperamental to permissions, environment variables, and in the case of the default system Python possibly versions of Python even older than 2.7.&lt;/P&gt;

&lt;P&gt;My suggestion is to check out a new app I've written called &lt;A href="https://splunkbase.splunk.com/app/4322/"&gt;PyDen&lt;/A&gt; which allows you to create Python virtual environments and install PyPI packages to the environment. You can then use these environments to execute custom commands and scripted inputs.&lt;/P&gt;

&lt;P&gt;This provides three key advantages:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;You can pick the version of Python you'd like to write in, including 3.5 to 3.7&lt;/LI&gt;
&lt;LI&gt;Create an isolated environment that won't interfere with imports in other apps (this can happen when packages are bundled into apps)&lt;/LI&gt;
&lt;LI&gt;Install any package available on PyPI to the environment&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Tue, 26 Feb 2019 05:46:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Scripted-Input-Python-Module-Error/m-p/455349#M78779</guid>
      <dc:creator>badarsebard</dc:creator>
      <dc:date>2019-02-26T05:46:35Z</dc:date>
    </item>
  </channel>
</rss>

