Myone Myone - 1 year ago 174
Python Question

Django runserver error (psycopg2)

I'm trying to do this:

python3.3 runserver

In my Django project folder. I get this error message:

File "/usr/local/lib/python3.3/site-packages/django/db/backends/postgresql_psycopg2/", line 25, in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named 'psycopg2'

My settings in are the following:

'default': {
'NAME': 'test_databas',
'USER': 'postgre',
'PASSWORD': 'mypassword',
'HOST': 'localhost',
'PORT': '5432',

I have already downloaded psycopg2 with Python3.3. The file /usr/local/lib/python3.3/site-packages/django/db/backends/postgresql_psycopg2/ also exists. However, Python doesn't think I have a module named psycopg2. I have tried this:

$ python3.3
Python 3.3.3 (default, Feb 2 2014, 14:32:49)
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'psycopg2'

I have also changed my sys.path as suggested here.

I'm new to this and would be very grateful for some help.

Answer Source

I check my local installation of psycopg2

apt-cache show python-psycopg2

Package: python-psycopg2

Priority: optional

Section: python

Installed-Size: 635


Source: psycopg2

Version: 2.4.5-1

Depends: python2.7, python (>= 2.7.1-0ubuntu2), python (<< 2.8), libc6 (>= 2.14), libpq5 (>= 8.3~)

So, python-psycopg2 installs you the version which is not compatible with python 3.x But also there is a a package named python3-psycopg2 When I check it, it looks like it is also Version: 2.4.5-1 but descriptive text tells it is compatible with python 3.2

apt-cache show python3-psycopg2

Package: python3-psycopg2

Priority: optional

Version: 2.4.5-1

Provides: python3.2-psycopg2

Depends: python3 (>= 3.2), python3 (<< 3.3), libc6 (>= 2.14), libpq5 (>= 8.3~)

Also, package sizes are different. Probably python3-psycopg2 is what you need, it was only mis-versioned on the documents.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download