Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django.core.exceptions.ImproperlyConfigured: Error loading psycopg module: No module named psycopg

Presently, I'm attempting to configure Django for use on a project, and am encountering a persistent error when I try to run python manage.py syncdb.

File "/x/x/x/x/x/x/base.py", line 23, in ?
    raise ImproperlyConfigured("Error loading psycopg module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg module: No module named psycopg

The other discussions of a similar problem that I have found both here and on other sites ended up being solved by the user downloading and installing psycopg, but unless I'm missing something critical, I've done that several times. I downloaded the tarball, unpacked it on my server, ran python setup.py build and python setup.py install with a --prefix directing it to my existing Python Path...I can go and navigate to the folder and see the various psycopg files, but for whatever reason, when I try to get my new project to sync up with the database, it cannot find psycopg and, as a result, won't talk to the db.

Notes: hostmonster.com account, have tried multiple release versions of psycopg2.

like image 300
user968270 Avatar asked Nov 23 '11 05:11

user968270


4 Answers

I had the error as well; although psycopg2 was installed on my system using apt-get, my virtualenv couldn't find it:

>>> import psycopg2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named psycopg2

It was fixed by doing a pip install psycopg2-binary inside the virtualenv (or pip install psycopg2 for <2.8 psycopg2 versions).

like image 114
SaeX Avatar answered Nov 13 '22 14:11

SaeX


I had this problem on a virtualenv in Ubuntu 18.4. I solved it by installing psycopg2 v2.7.4:

pip install psycopg2==2.7.4
like image 35
Heron Rossi Avatar answered Nov 13 '22 13:11

Heron Rossi


type pip install psycopg2-binary inside the virtualenv worked for me

like image 22
Mohamed Atef Avatar answered Nov 13 '22 15:11

Mohamed Atef


Try to use this:

sudo apt-get install python-psycopg2
like image 11
Stone Avatar answered Nov 13 '22 13:11

Stone