This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.

⚠️ We've moved!

Hi there!

To reduce project dependency on 3rd party paid services the StackStorm TSC has decided to move the Q/A from this forum to Github Discussions. This will make user experience better integrated with the native Github flow, as well as the questions closer to the community where they can provide answers.

Use 🔗 Github Discussions to ask your questions.

Module import failed in python

hi team im trying to integrate postgresql with stackstorm and establishing connection using python but im unable to import psycopg2
my code is executing in python but in stackstorm I’m getting the following error


Traceback (most recent call last):
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/runners/", line 216, in _get_action_instance
    actions_cls = action_loader.register_plugin(Action, self._file_path)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/util/", line 165, in register_plugin
    module = imp.load_source(module_name, plugin_abs_file_path)
  File "/opt/stackstorm/packs/postgres/actions/", line 1, in <module>
    import psycopg2
ImportError: No module named psycopg2 

I have tried installing psycopg2 it got installed successfully but still I’m facing the same error


You’ll need to install that dependency in your pack’s virtualenv:

source /opt/stackstorm/virtualenv/<pack_name>/bin/activate
pip install pyscopg2

Ideally you should place this dependency in your pack’s requirements.txt file so that it’s installed in your virtualenv in the future: Create and Contribute a Pack — StackStorm 2.6.0 documentation


I went to this path /opt/stackstorm/virtualenv/<pack_name>/bin/
and found activate file next i have tried running this command but I’m getting this

Collecting pyscopg2
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see
  Could not find a version that satisfies the requirement pyscopg2 (from versions: )
No matching distribution found for pyscopg2

@cristi how would you normally install that package in a Python virtualenv? Looks like you need to do it a little differently - see

@nmaludy @lhill Thank you its working :slight_smile:

1 Like