Getting Data In

Scripted Input - Python Module Error


I have a python script that pulls data from an SFTP source and writes the data to a file ( 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 (

I can run the bash script from the command line fine. However, when I try to run it using Splunk (./splunk cmd /opt/splunk/etc/apps/myApp/bin/, I get a module import error.

I'm not sure what I am doing wrong. Anyone have any suggestions?


Traceback (most recent call last):
  File "./", line 4, in <module>
    import pysftp
ImportError: No module named pysftp

#!/usr/bin/env python

import json
import pysftp
import openpyxl



echo myScript is starting >&2

cd $( dirname "${BASH_SOURCE[0]}" )

exec /usr/bin/python ./
0 Karma


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.

My suggestion is to check out a new app I've written called PyDen 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.

This provides three key advantages:

  1. You can pick the version of Python you'd like to write in, including 3.5 to 3.7
  2. Create an isolated environment that won't interfere with imports in other apps (this can happen when packages are bundled into apps)
  3. Install any package available on PyPI to the environment
0 Karma



I think you have installedpysftp files in local python. So you should add path in your script OR you have to copy those file into splunk lib.

See below ref link for your more info:

0 Karma


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.

0 Karma


Also, I thought the point of the wrapper script was to call the .py script using standard python?

0 Karma
Get Updates on the Splunk Community!

Maximize the Value from Microsoft Defender with Splunk

 Watch NowJoin Splunk and Sens Consulting for this Security Edition Tech TalkWho should attend:  Security ...

This Week's Community Digest - Splunk Community Happenings [6.27.22]

Get the latest news and updates from the Splunk Community here! News From Splunk Answers ✍️ Splunk Answers is ...

Reminder! Splunk Love Promo: $25 Visa Gift Card for Your Honest SOAR Review With ...

We recently launched our first Splunk Love Special, and it's gone phenomenally well, so we're doing it again, ...