尝试设置我的Django项目以使用postgres。我在Windows 10上使用Python 3.5.1。使用easy_install从http://www.stickpeople.com/projects/python/win-psycopg/为Python 3.5安装psycopg。我正在https://djangogirls.gitbooks.io/django-girls-tutorial-extensions/content/optional_postgresql_installation/index.html跟踪指南,但当我尝试导入psycopg2以验证安装成功时,我得到:
(venv) D:\Projects\webcomic>python -c "import psycopg2"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "D:\Projects\webcomic\venv\lib\site-packages\psycopg2-2.6.1-py3.5-win32.egg\psycopg2\__init__.py", line 50, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: No module named 'psycopg2._psycopg'
不确定该怎么做。对于它的价值,我的sys.path看起来像
>>> pprint(sys.path)
['',
'D:\\Projects\\webcomic\\venv\\lib\\site-packages\\psycopg2-2.6.1-py3.5-win32.egg',
'D:\\Projects\\webcomic\\venv\\Scripts\\python35.zip',
'D:\\Projects\\webcomic\\venv\\DLLs',
'D:\\Projects\\webcomic\\venv\\lib',
'D:\\Projects\\webcomic\\venv\\Scripts',
'c:\\users\\user\\appdata\\local\\programs\\python\\python35-32\\Lib',
'c:\\users\\user\\appdata\\local\\programs\\python\\python35-32\\DLLs',
'D:\\Projects\\webcomic\\venv',
'D:\\Projects\\webcomic\\venv\\lib\\site-packages']
答案 0 :(得分:1)
转到venv/Lib/site-packages
,然后删除那里的任何psycopg2相关文件或文件夹,然后运行以下命令:
pip install psycopg2
N.B。确保venv仍在运行。
要确保正确导入,请运行python manage.py migrate
,它应该运行时没有任何错误。
希望我帮忙!