简体   繁体   中英

Django: Error loading psycopg2

I was following the GeoDjango tutorial ( https://docs.djangoproject.com/en/1.8/ref/contrib/gis/tutorial/#geographic-models ) and got to the migrate step, and I am getting the error "cannot import name util". I'm not sure what the problem is. Also, ENGINE is set to 'django.contrib.gis.db.backends.postgis' in the settings.py file. Does anyone know how to fix this? Thanks!

$ python manage.py makemigrations
...
__import__(name)
  File "//anaconda/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/base.py", line 3, in <module>
    from django.db.backends.postgresql_psycopg2.base import \
  File "//anaconda/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 20, in <module>
    raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: cannot import name util

I figured out how to solve it. I will provide details in case anyone else has this problem and reads this post: I ended up downloading the source package from http://initd.org/psycopg/download/ . Then, I followed the instructions under "Use the source package" at this page: http://initd.org/psycopg/docs/install.html . Before entering commands in Terminal, I went into the psycopg2-2.6 folder in Downloads and manually edited the path in the setup.cfg file. You have to uncomment the line "pg_config=" and then enter the path to pg_config, which can be found using Finder on a Mac. (As an example, the path to pg_config on my computer is /opt/local/lib/postgresql93/bin/pg_config) The following is a list of the commands I used in Terminal:

$ cd Downloads
$ cd psycopg2-2.6
$ python setup.py build
$ sudo python setup.py install

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM