简体   繁体   English

在ubuntu 14.04上安装psycopg2的最佳方法

[英]Best way to install psycopg2 on ubuntu 14.04

I am having trouble installing a Django app ( Mezzanine ) on Ubuntu 14.04. 我在Ubuntu 14.04上安装Django应用程序( Mezzanine )时遇到问题。 I've installed most necessities using apt-get (except for django-compressor and south -used pip), including psycopg2 for Postgres. 我使用apt-get安装了大多数必需品(除了django-compressor和south -used pip),包括用于Postgres的psycopg2。 However when I go to run python manage.py createdb it gives this error: 但是,当我去运行python manage.py createdb时,它会出现以下错误:

Error loading psycopg2 module: No module named psycopg2

This is the command I'm using to install psycopg2: 这是我用来安装psycopg2的命令:

sudo apt-get install python-psycopg2

What am I doing wrong? 我究竟做错了什么? Should I use pip to install psycopg2. 我应该使用pip来安装psycopg2。 I went to the website and it recommends installing through your OS package manager instead of pip. 我去了网站,它建议通过你的操作系统包管理器而不是pip进行安装。

I am working in a virtualenv except for when I am installing the psycopg2 elements.... 我在virtualenv工作,除了我安装psycopg2元素....

If you need psycopg2 for a system installed program, then install it with the system package manager. 如果您需要psycopg2用于系统安装的程序,请使用系统软件包管理器进行安装。 If you need it for a program in a virtualenv, install it in that virtualenv. 如果你需要它用于virtualenv中的程序,请将其安装在virtualenv中。

. env/bin/activate
pip install psycopg2

Note that on many distros, the development headers needed for compiling against libraries are not installed by default. 请注意,在许多发行版中,默认情况下不会安装编译库所需的开发头。 For psycopg2 on Ubuntu you'll need the python and postgresql headers. 对于Ubuntu上的psycopg2,你需要python和postgresql头文件。

sudo apt-get install python-dev libpq-dev

psycopg 2.7 now issues a warning that it will stop providing binary releases due to compatibility issues. psycopg 2.7现在发出警告,由于兼容性问题,它将停止提供二进制版本。

The psycopg2 wheel package will be renamed from release 2.8; psycopg2 wheel包将从2.8版重命名; in order to keep installing from binary please use "pip install psycopg2-binary" instead. 为了继续从二进制安装,请使用“pip install psycopg2-binary”代替。 For details see: http://initd.org/psycopg/docs/install.html#binary-install-from-pypi . 有关详细信息,请参阅: http//initd.org/psycopg/docs/install.html#binary-install-from-pypi

See the release announcement for a thorough explanation. 有关详细说明,请参阅发布公告 To handle the warning, tell pip not to download the pre-built wheel for psycopg2. 要处理警告,请告诉pip不要下载psycopg2的预置轮。

pip install --no-binary psycopg2 psycopg2

For me, to resolve this issue on Ubuntu 14.04 with virtualenv I had to 对我来说,我必须使用virtualenv在Ubuntu 14.04上解决这个问题

sudo apt-get install python3.5-dev

then I could run 然后我就可以跑了

pip install psycopg2

The psycopg you installed through apt-get is not visible from inside the virtual env. 您通过apt-get安装的psycopg在虚拟环境中是不可见的。

You should install it through pip 你应该通过pip安装它

pip install psycopg2

after sourcing your environment. 在采购您的环境之后。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM