Django 到 PostgreSQL:加载 psycopg2 时出错
尝试使用 db['ENGINE'] = 'django.db.backends.psycopg2'
来 runserver
我得到:
[...]
File "/usr/local/lib/python2.6/dist-packages/django/db/backends/psycopg2/__init__.py", line 67, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
File "/usr/local/lib/python2.6/dist-packages/psycopg2-2.4.4-py2.6-linux-x86_64.egg/psycopg2/__init__.py", line 67, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: /usr/local/lib/python2.6/dist-packages/psycopg2-2.4.4-py2.6-linux-x86_64.egg/psycopg2/_psycopg.so: undefined symbol: Py_InitModule4_64
with 'ENGINE': 'django.db. backends.postgresql_psycopg2'
我得到:
[...]
File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/lib/python2.6/dist-packages/django/db/backends/postgresql_psycopg2/base.py", line 24, in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: /usr/local/lib/python2.6/dist-packages/psycopg2-2.4.4-py2.6-linux-x86_64.egg/psycopg2/_psycopg.so: undefined symbol: Py_InitModule4_64
而且我不应该将 psycopg 与 Python >2.6 一起使用,对吗?
对如何使这项工作有任何帮助吗?
Trying to runserver
with db['ENGINE'] = 'django.db.backends.psycopg2'
I got :
[...]
File "/usr/local/lib/python2.6/dist-packages/django/db/backends/psycopg2/__init__.py", line 67, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
File "/usr/local/lib/python2.6/dist-packages/psycopg2-2.4.4-py2.6-linux-x86_64.egg/psycopg2/__init__.py", line 67, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: /usr/local/lib/python2.6/dist-packages/psycopg2-2.4.4-py2.6-linux-x86_64.egg/psycopg2/_psycopg.so: undefined symbol: Py_InitModule4_64
with 'ENGINE': 'django.db.backends.postgresql_psycopg2'
I got :
[...]
File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/lib/python2.6/dist-packages/django/db/backends/postgresql_psycopg2/base.py", line 24, in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: /usr/local/lib/python2.6/dist-packages/psycopg2-2.4.4-py2.6-linux-x86_64.egg/psycopg2/_psycopg.so: undefined symbol: Py_InitModule4_64
And I shouldn't use psycopg with Python >2.6, right ?
Any help on how to do make this work ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试重新开始。准备独立的virtualenv目录。
激活 virtualenv
准备 django 和 psycopg2 以及您使用的任何其他库
,然后移动到您的项目目录(带有manage.py),确保项目位于 PYTHONPATH 中并再次尝试
./manage.py runserver
。Try make a clean slate. Prepare separated virtualenv directory.
Activate virtualenv
Prepare django and psycopg2 and whatever other libraries you use
And then move to your project directory (this with manage.py), make sure project is within PYTHONPATH and try
./manage.py runserver
again.您的安装已损坏。也许你运行的是 32 位 python,但该库适用于 64 位。
我用 Python2.7 运行 psycopg2 没有问题。
Your installation is broken. Maybe you run a 32bit python but the library is for 64bit.
I run psycopg2 with Python2.7 without problems.