python manage.py migration出现问题

编程入门 行业动态 更新时间:2024-10-28 06:22:32
本文介绍了python manage.py migration出现问题->没有名为psycopg2的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在使用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出现问题

本文发布于:2023-10-28 00:33:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534981.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:manage   python   migration   py

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!