2012-02-10 80 views
1

試圖runserverdb['ENGINE'] = 'django.db.backends.psycopg2'我:的Django到PostgreSQL:錯誤加載psycopg2

[...] 
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 

'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 

而且我不應該與Python> 2.6使用psycopg吧?

如何做這項工作的任何幫助?

回答

2

嘗試做一個乾淨的石板。準備分離的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

+0

自從我寫這個答案以來,我的知識增加了,現在我強烈建議熟悉virtualenvwrapper庫:https://virtualenvwrapper.readthedocs.io/en/latest/。當您進行初始設置時,通過它管理virtualenvs會更容易。 – omikron 2016-09-07 08:51:36

1

您的安裝已損壞。也許你運行一個32位的Python,但庫是64位。

我用Python2.7運行psycopg2沒有問題。

相關問題