Django 到 PostgreSQL:加载 psycopg2 时出错

发布于 2025-01-04 08:11:55 字数 1372 浏览 1 评论 0原文

尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花间憩 2025-01-11 08:11:56

尝试重新开始。准备独立的virtualenv目录。

sudo apt-get install python-virtualenv  # if you don't have it yet 
virtualenv /some/dir/

激活 virtualenv

source /some/dir/bin/activate

准备 django 和 psycopg2 以及您使用的任何其他库

pip install psycopg2 django # possibly other libraries

,然后移动到您的项目目录(带有manage.py),确保项目位于 PYTHONPATH 中并再次尝试 ./manage.py runserver

Try make a clean slate. Prepare separated virtualenv directory.

sudo apt-get install python-virtualenv  # if you don't have it yet 
virtualenv /some/dir/

Activate virtualenv

source /some/dir/bin/activate

Prepare django and psycopg2 and whatever other libraries you use

pip install psycopg2 django # possibly other libraries

And then move to your project directory (this with manage.py), make sure project is within PYTHONPATH and try ./manage.py runserver again.

往日情怀 2025-01-11 08:11:56

您的安装已损坏。也许你运行的是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文