[python] ImportError: No module named psycopg2

When installing process of OpenERP 6, I want to generate a config file with this command,

cd /home/openerp/openerp-server/bin/

./openerp-server.py -s --stop-after-init -c /home/openerp/openerp-server.cfg

But it was always showed a message

ImportError: No module named psycopg2

When I check for psycopg2 package, it's already installed,

Package python-psycopg2-2.4.5-1.rhel5.x86_64 already installed and latest version

Nothing to do

What's wrong with this?

My server is CentOS, I've installed python 2.6.7.

This question is related to python centos odoo centos5

The answer is


i have the same problem, but this piece of snippet alone solved my problem.

pip install psycopg2

Run into the same issue when i switch to ubuntu from windows 10.. the following worked for me.. this after googling and trying numerous suggestions for 2 hours...

sudo apt-get install libpq-dev, then pip3 install psycopg2

I hope this helps someone who has encountered the same problem especially when switching for windows OS to linux(ubuntu).


I faced same problem and waste almost a day to resolve this issue . I have done 2 things 1- use python 3.6 instead of 3.8 2- change django 2.2 version(may be working some higher but i change to 2.2)

Now its working fine


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.


sudo pip install psycopg2-binary

Try installing

psycopg2-binary

with pip install psycopg2-binary --user


For Python3

Step 1: Install Dependencies

sudo apt-get install python3 python-dev python3-dev

Step 2: Install

pip install 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 

Ref: Fernando Munoz


check correctly if you had ON your virtual env of your peoject, if it's OFF then make it ON. execute following cammands:

workon <your_env_name>
python manage.py runserver

It's working for me


You need to install the psycopg2 module.

On CentOS: Make sure Python 2.7+ is installed. If not, follow these instructions: http://toomuchdata.com/2014/02/16/how-to-install-python-on-centos/

# Python 2.7.6:
$ wget http://python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
$ tar xf Python-2.7.6.tar.xz
$ cd Python-2.7.6
$ ./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
$ make && make altinstall
$ yum install postgresql-libs

# First get the setup script for Setuptools:
$ wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py

# Then install it for Python 2.7 and/or Python 3.3:
$ python2.7 ez_setup.py

$ easy_install-2.7 psycopg2

Even though this is a CentOS question, here are the instructions for Ubuntu:

$ sudo apt-get install python3-pip python-distribute python-dev
$ easy_install psycopg2

Cite: http://initd.org/psycopg/install/


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

sudo apt-get install libpq-dev
pip install psycopg2

Recently faced this issue on my production server. I had installed pyscopg2 using

sudo pip install psycopg2

It worked beautifully on my local, but had me for a run on my ec2 server.

sudo python -m pip install psycopg2

The above command worked for me there. Posting here just in case it would help someone in future.


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


For python3 on ubuntu, this worked for me:

$sudo apt-get update
$sudo apt-get install libpq-dev
$sudo pip3 install psycopg2-binary

Try with these:

virtualenv -p /usr/bin/python3 test_env
source test_env/bin/activate
pip install psycopg2

run python and try to import if you insist on installing it on your systems python try:

pip3 install psycopg2

Examples related to python

programming a servo thru a barometer Is there a way to view two blocks of code from the same file simultaneously in Sublime Text? python variable NameError Why my regexp for hyphenated words doesn't work? Comparing a variable with a string python not working when redirecting from bash script is it possible to add colors to python output? Get Public URL for File - Google Cloud Storage - App Engine (Python) Real time face detection OpenCV, Python xlrd.biffh.XLRDError: Excel xlsx file; not supported Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation

Examples related to centos

How to uninstall an older PHP version from centOS7 Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details pip install - locale.Error: unsupported locale setting ssh : Permission denied (publickey,gssapi-with-mic) How to change the MySQL root account password on CentOS7? Completely remove MariaDB or MySQL from CentOS 7 or RHEL 7 ffprobe or avprobe not found. Please install one How to check all versions of python installed on osx and centos Cannot find java. Please use the --jdkhome switch VirtualBox: mount.vboxsf: mounting failed with the error: No such device

Examples related to odoo

dictionary update sequence element #0 has length 3; 2 is required ImportError: No module named psycopg2

Examples related to centos5

ImportError: No module named psycopg2 How can git be installed on CENTOS 5.5?