1

I am trying to get Django and PostgreSQL to work.

So far I am getting the following error when I run syncdb.

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

The following is my settings.py.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'mydb',                      # Or path to database file if using sqlite3.
        'USER': 'username',                  # Not used with sqlite3.
        'PASSWORD': 'pwd123',                # Not used with sqlite3.
        'HOST': 'localhost',                 # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '5432',                      # Set to empty string for default. Not used with sqlite3.
    }
}

I think I have installed psycopg2 correctly, but I am not sure (through MacPorts).

Is there a way whether I can check whether psycopg2 is installed?

This link contains the install log of psycopg2

UPDATE

I got it working with the method below, but how do I check whether psycopg2 was actually installed before? and if so how to remove it completely?

1
  • I've had no luck using MacPorts for Django development, it never seems to install the right versions or in a compatible. Use easyinstall as Pablo suggests. Also, I use virtualenv and don't I don't touch the base python install which helps a lot. Commented Aug 6, 2011 at 14:23

1 Answer 1

5

If you are using MAC, make sure psycopg2 is installed and accesible to your main python interpreter.

This is how I'd install it on a mac:

$ sudo easy_install django
$ sudo easy_install psycopg2

Then test it:

$ python
>>> import django
>>> import psycopg2

You should not get any errors.

Also, if you are using an Eclipse/PYDEV, make sure you reconfigure your interpreter after installing django and psycopg2 libraries.

Sign up to request clarification or add additional context in comments.

2 Comments

I've got django smooth and running and im using pycharm, it has been running great and I am only having problems with psycopg2. Is there a way to uninstall the current psycopg2 that I have? and install with easy_install instead?
Just try the easy_install anyway. I think psycopg2 needs postgresql libraries to compile, so you might as well try installing postgresql client libraries. I have mine installed from EnterpriseDB installer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.