ImportError: No module named psycopg2 ImportError: No module named psycopg2 python python

ImportError: No module named psycopg2


Step 1: Install the dependencies

sudo apt-get install build-dep python-psycopg2

Step 2: Run this command in your virtualenv

pip install psycopg2-binary 

Ref: Fernando Munoz


Use psycopg2-binary instead of psycopg2.

pip install psycopg2-binary

Or you will get the warning below:

UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: http://initd.org/psycopg/docs/install.html#binary-install-from-pypi.

Reference: Psycopg 2.7.4 released | Psycopg


I faced the same issue and resolved it with following commands:

sudo apt-get install libpq-devpip install psycopg2