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-dev
pip install psycopg2
Try installing
psycopg2-binary
with
pip install psycopg2-binary --user
Please try to run the command import psycopg2
on the python console. If you get the error then check the sys.path
where the python look for the install module. If the parent directory of the python-psycopg2-2.4.5-1.rhel5.x86_64
is there in the sys.path
or not. If its not in the sys.path
then run export PYTHONPATH=<parent directory of python-psycopg2-2.4.5-1.rhel5.x86_64>
before running the openerp server.