ImportError: No module named psycopg2
Solution 1
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
Solution 2
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
Solution 3
I faced the same issue and resolved it with following commands:
sudo apt-get install libpq-dev
pip install psycopg2
Solution 4
Try installing
psycopg2-binary
with
pip install psycopg2-binary --user
Solution 5
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.
Related videos on Youtube
ws_123
Updated on July 08, 2022Comments
-
ws_123 almost 2 years
In installation process of OpenERP 6, I want to generate a config file with these commands:
cd /home/openerp/openerp-server/bin/
./openerp-server.py -s --stop-after-init -c /home/openerp/openerp-server.cfg
But it always showed the message:
ImportError: No module named psycopg2
When I checked for psycopg2 package, it's already installed. Package
python-psycopg2-2.4.5-1.rhel5.x86_64
is already installed to its latest version. Nothing to do. What's wrong with this? My server is CentOS, I've installed Python 2.6.7.-
John Lyon over 11 yearsYou need to accept some answers on some of your other questions.
-
Keith over 11 yearsThe package installs for python2.4. If you have manually installed 2.6 then you also have to install all the other packages for 2.6.
-
Taizo Ito over 11 yearsPlease execute the following command to confirm the python system path.
$ python -c 'import sys; print sys.path'
-
Nilesh over 11 yearsWill you please try to
import psycopg2
on the python console? -
Nilesh over 11 yearsIf you got the answer then select the answer.
-
hassanzadeh.sd about 4 years
pip install psycopg2
-
-
aliteralmind almost 10 yearsThis saved me! stackoverflow.com/questions/25169939/…
-
JcKelley over 9 yearsI had to run
easy_install psycopg2
, but your question led me there! -
Adam Parkin over 8 yearsI found I also had to
sudo apt-get install libpq-dev
, as I don't have Postgresql installed on the machine I'm trying to installpsycopg2
on. -
Stephan Schielke almost 8 yearsOn arch linux its the same package-name:
pacman -S python-psycopg2
-
alekwisnia over 7 yearsFor Python3 users: install
libpq-dev postgresql
-
Mugoma J. Okomba over 7 yearsOn Kubuntu 16.04
build-dep
option doesn't work butsudo apt-get install python-psycopg2
works -
Harun-Ur-Rashid over 6 yearsin ubuntu 16.04 it shows E: Unable to locate package build-dep
-
Arthur over 6 yearsHmm getting
ez_setup.py is deprecated and when using it setuptools will be pinned to 33.1.1
-
Bennett Garner over 5 yearsYou can't use install and build-dep in the same command. They're both commands for apt-get. Should be
sudo apt-get build-dep python-psycopg2
-
webelo over 4 yearsThis fixed the error message
You need to install postgresql-server-dev-X.Y ...
that I got after runningsudo apt-get install build-dep python-psycopg2
(even thought I have postgresql installed already). -
Brian about 4 yearsThis is the only answer that worked for me with
python 3.7.3
anddjango 3.0.2
-
Muhammad Inaam Munir about 4 yearswhat is --user for?
-
ibnɘꟻ over 3 years@MuhammadInaamMunir
--user : Install to the Python user install directory for your platform. Typically ~/.local/, or %APPDATA%\Python on Windows.
You can check more info usingpip install --help
. -
Aramis NSR over 3 yearsthanks this helped instead of other top answers
-
Chad about 3 yearsJust FYI - "If you are the maintainer of a published package depending on psycopg2 you shouldn’t use psycopg2-binary as a module dependency" see: psycopg.org/docs/install.html#psycopg-vs-psycopg-binary
-
Iris D about 2 yearsThis solved my problem! psycopg2 was clearly installed because i could successfully connect to my db, but when I tried to run a streamlit app that needed the results from the connection, i got the import not found statement. This solved it completely. Thank you!