I am having some trouble with migrating Django using postgresql.
我使用postgresql迁移Django时遇到了一些麻烦。
This is my first time with Django, and I am just following the tutorial.
这是我第一次使用Django,我只是按照教程。
As suggested on the Django website, I have created a virtualenv to run the Django project.
正如Django网站上所建议的那样,我创建了一个运行Django项目的virtualenv。
Next, I created a postgresql database with these settings:
接下来,我使用以下设置创建了一个postgresql数据库:
In settings.py I have set these values for the database:
在settings.py中,我为数据库设置了以下值:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'django_tutorial',
'USER': 'johan',
'PASSWORD': '1234',
}
}
When installing psycopg2 with apt-get I get this message:
使用apt-get安装psycopg2时,我收到以下消息:
(venv)johan@johan-pc:~/sdp/django_tutorial/venv/django_tutorial$ sudo apt-get install python-psycopg2
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-psycopg2 is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 95 not upgraded.
As far as I can tell this would mean that psycopg2 is installed.
据我所知,这意味着安装了psycopg2。
When running
跑步时
$python manage.py migrate
I get the following error message:
我收到以下错误消息:
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named psycopg2
If needed for the answer I could provide the entire stack trace.
如果答案需要,我可以提供整个堆栈跟踪。
Could someone explain what I could do to solve this? I have also looked on Google for a solution with no luck.
有人可以解释我能做些什么来解决这个问题吗?我也在谷歌寻找一个没有运气的解决方案。
2 个解决方案
#1
7
It must be because you are installing psycopg2 in your system level python installation not in your virtualenv.
这一定是因为你在系统级python安装中安装psycopg2而不是你的virtualenv。
sudo apt-get install python-psycopg2
will install it in your system level python installation.
将它安装在您的系统级python安装中。
You can install it in your virtualenv by
你可以在你的virtualenv中安装它
pip install psycopg2
after activating your virtualenv or you can create your virtualenv with --system-site-packages
flag so that your virtualenv will have packages in your system level python already available.
激活你的virtualenv之后,或者你可以用--system-site-packages标志创建你的virtualenv,这样你的virtualenv就会有你系统级python的包。
virtualenv --system-site-packages test
where test
is your virtualenv.
测试是你的virtualenv。
#2
0
It's because you use Django in a python virtualenv and as stated on virtualenv web site :
这是因为你在一个python virtualenv中使用Django,并且如virtualenv网站所述:
It creates an environment that has its own installation directories, that doesn’t share libraries with other virtualenv environments (and optionally doesn’t access the globally installed libraries either).
它创建了一个具有自己的安装目录的环境,该环境不与其他virtualenv环境共享库(并且可选地也不访问全局安装的库)。
That means that you need to install psycopg2 in your virtualenv and not globaly or make it access globaly installed libraries.
这意味着您需要在virtualenv中安装psycopg2而不是globaly,或者让它访问全局安装的库。
#1
7
It must be because you are installing psycopg2 in your system level python installation not in your virtualenv.
这一定是因为你在系统级python安装中安装psycopg2而不是你的virtualenv。
sudo apt-get install python-psycopg2
will install it in your system level python installation.
将它安装在您的系统级python安装中。
You can install it in your virtualenv by
你可以在你的virtualenv中安装它
pip install psycopg2
after activating your virtualenv or you can create your virtualenv with --system-site-packages
flag so that your virtualenv will have packages in your system level python already available.
激活你的virtualenv之后,或者你可以用--system-site-packages标志创建你的virtualenv,这样你的virtualenv就会有你系统级python的包。
virtualenv --system-site-packages test
where test
is your virtualenv.
测试是你的virtualenv。
#2
0
It's because you use Django in a python virtualenv and as stated on virtualenv web site :
这是因为你在一个python virtualenv中使用Django,并且如virtualenv网站所述:
It creates an environment that has its own installation directories, that doesn’t share libraries with other virtualenv environments (and optionally doesn’t access the globally installed libraries either).
它创建了一个具有自己的安装目录的环境,该环境不与其他virtualenv环境共享库(并且可选地也不访问全局安装的库)。
That means that you need to install psycopg2 in your virtualenv and not globaly or make it access globaly installed libraries.
这意味着您需要在virtualenv中安装psycopg2而不是globaly,或者让它访问全局安装的库。