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?

bash-
  • 6,144
  • 10
  • 43
  • 51
  • 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. – Rob Osborne Aug 06 '11 at 14:23

1 Answers1

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.

Pablo Santa Cruz
  • 176,835
  • 32
  • 241
  • 292
  • 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? – bash- Aug 06 '11 at 14:27
  • 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. – Pablo Santa Cruz Aug 06 '11 at 15:51