python manage.py migration出现问题->没有名为psycopg2的模块 [英] trouble with python manage.py migrate -> No module named psycopg2

查看:114
本文介绍了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出现问题->没有名为psycopg2的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆