8

I want to use postgresql with django so did the following:

sudo apt-get install libpq-dev python-dev
sudo apt-get update
workon myenv
sudo pip install psycopg2

And after configuring my settings.py correctly, I run

./manage.py syncdb

But an exception gets thrown:

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

The database configuration:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'mydb',
        'USER': 'postgres',
        'PASSWORD': 'password1234',
        'HOST': 'localhost',
        'PORT': '',
    }
}
xofer
  • 3,052
  • 12
  • 19

1 Answers1

4

Installing with sudo (sudo pip install ...) causes the installed files to be owned by root, and Django (run without sudo) cannot read them. You can sudo pip uninstall psycopg2 and then install without sudo. (If that doesn't work, try sudo chown -R $USER ~/.virtualenvs/myvenv first (assumes that's your virtualenv path).

xofer
  • 3,052
  • 12
  • 19