Module import failed in python

python
virtualenv

#1

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

ERROR:

Traceback (most recent call last):
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/runners/python_action_wrapper.py", 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/loader.py", line 165, in register_plugin
    module = imp.load_source(module_name, plugin_abs_file_path)
  File "/opt/stackstorm/packs/postgres/actions/sha.py", 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


(Nick Maludy) #2

Cristi,

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

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

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


#3

@nmaludy

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

ERROR:
Collecting pyscopg2
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:318: 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 https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: 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 https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Could not find a version that satisfies the requirement pyscopg2 (from versions: )
No matching distribution found for pyscopg2

(Lindsay Hill) #4

@cristi how would you normally install that package in a Python virtualenv? Looks like you need to do it a little differently - see http://initd.org/psycopg/docs/install.html#binary-install-from-pypi


#5

@nmaludy @lhill Thank you its working :slight_smile: