我在使用postgresql迁移Django时遇到了一些麻烦.
I am having some trouble with migrating Django using postgresql.
这是我第一次使用Django,而我只是在学习本教程.
This is my first time with Django, and I am just following the tutorial.
按照Django网站上的建议,我创建了一个virtualenv来运行Django项目.
As suggested on the Django website, I have created a virtualenv to run the Django project.
接下来,我使用以下设置创建了一个postgresql数据库:
Next, I created a postgresql database with these settings:
在settings.py中,我为数据库设置了以下值:
In settings.py I have set these values for the database:
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'django_tutorial', 'USER': 'johan', 'PASSWORD': '1234', } }使用apt-get安装psycopg2时,出现以下消息:
When installing psycopg2 with apt-get I get this message:
(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.据我所知,这意味着已安装psycopg2.
As far as I can tell this would mean that psycopg2 is installed.
运行时
$python manage.py migrate我收到以下错误消息:
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named psycopg2如果需要答案,我可以提供整个堆栈跟踪.
If needed for the answer I could provide the entire stack trace.
有人可以解释一下我可以做些什么来解决这个问题吗?我也曾在Google上寻找没有运气的解决方案.
Could someone explain what I could do to solve this? I have also looked on Google for a solution with no luck.
推荐答案必须是因为要在系统级别的python安装中而不是在virtualenv中安装psycopg2.
It must be because you are installing psycopg2 in your system level python installation not in your virtualenv.
sudo apt-get install python-psycopg2将其安装到您的系统级python安装中.
will install it in your system level python installation.
您可以通过以下方式将其安装到您的virtualenv中:
You can install it in your virtualenv by
pip install psycopg2在激活您的virtualenv之后,或者您可以使用--system-site-packages标志创建virtualenv,以便您的virtualenv在系统级python中已经有可用的软件包.
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 test其中test是您的虚拟环境.
更多推荐
python manage.py migration出现问题
发布评论