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

user968270 picture user968270 · Nov 23, 2011 · Viewed 67.1k times · Source

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.

Answer

SaeX picture SaeX · Mar 15, 2014

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).