我正在Amazon EC2服务器上安装python 3.5,django 1.10和psycopg2 2.7.1,以便使用Postgresql数据库。我在虚拟环境中使用python 3,并遵循经典的安装步骤:
cd /home/mycode
virtualenv-3.5 p3env
source p3env/bin/activate
pip install django
cd kenbot
django-admin startproject kenbot
pip install psycopg2
Run Code Online (Sandbox Code Playgroud)
然后,我在项目中编辑了settings.py文件,以定义DATABASE设置:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'deleted',
'USER': 'deleted',
'PASSWORD': 'deleted',
'HOST': 'deleted',
'PORT': '5432',
}
Run Code Online (Sandbox Code Playgroud)
最后,我键入(仍然在虚拟环境中):
python manage.py makemigrations
Run Code Online (Sandbox Code Playgroud)
并得到以下错误:
Traceback (most recent call last):
File "/home/mycode/p3env/local/lib/python3.5/dist-packages/django/db/backends/postgresql/base.py", line 20, in <module>
import psycopg2 as Database
ImportError: No module named 'psycopg2'
During handling of the above exception, another exception occurred:
Traceback (most recent call …Run Code Online (Sandbox Code Playgroud)