问题:您需要安装postgresql-server-dev-XY来构建服务器端扩展,或者安装libpq-dev来构建客户端应用程序

我正在使用virtualenv处理Django项目,并将其连接到本地postgres数据库。当我运行项目时说,

ImportError: No module named psycopg2.extensions

然后我用这个命令来安装

pip install psycopg2

然后在安装过程中会出现以下错误。

Downloading/unpacking psycopg2==2.4.4
  Downloading psycopg2-2.4.4.tar.gz (648kB): 648kB downloaded
  Running setup.py (path:/home/muhammadtaqi/Projects/MyProjects/OnlineElectionCampaign/venv/build/psycopg2/setup.py) egg_info for package psycopg2

    Error: You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.

    Complete output from command python setup.py egg_info:
    running egg_info

creating pip-egg-info/psycopg2.egg-info

writing pip-egg-info/psycopg2.egg-info/PKG-INFO

writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt

writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt

writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'

warning: manifest_maker: standard file '-c' not found



Error: You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.



----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /home/muhammadtaqi/Projects/MyProjects/OnlineElectionCampaign/venv/build/psycopg2
Storing debug log for failure in /home/muhammadtaqi/.pip/pip.log

I am working on Django project with virtualenv and connect it to local postgres database. when i run the project is says,

ImportError: No module named psycopg2.extensions

then i used this command to install

pip install psycopg2

then during the installation it gives following error.

Downloading/unpacking psycopg2==2.4.4
  Downloading psycopg2-2.4.4.tar.gz (648kB): 648kB downloaded
  Running setup.py (path:/home/muhammadtaqi/Projects/MyProjects/OnlineElectionCampaign/venv/build/psycopg2/setup.py) egg_info for package psycopg2

    Error: You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.

    Complete output from command python setup.py egg_info:
    running egg_info

creating pip-egg-info/psycopg2.egg-info

writing pip-egg-info/psycopg2.egg-info/PKG-INFO

writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt

writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt

writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'

warning: manifest_maker: standard file '-c' not found



Error: You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.



----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /home/muhammadtaqi/Projects/MyProjects/OnlineElectionCampaign/venv/build/psycopg2
Storing debug log for failure in /home/muhammadtaqi/.pip/pip.log

回答 0

使用以下命令,将解决错误:

sudo apt-get install postgresql

然后开火:

sudo apt-get install python-psycopg2

最后:

sudo apt-get install libpq-dev

Use these following commands, this will solve the error:

sudo apt-get install postgresql

then fire:

sudo apt-get install python-psycopg2

and last:

sudo apt-get install libpq-dev

回答 1

我只是从终端以root身份运行此命令,问题就解决了,

sudo apt-get install -y postgis postgresql-9.3-postgis-2.1
pip install psycopg2

要么

sudo apt-get install libpq-dev python-dev
pip install psycopg2

I just run this command as a root from terminal and problem is solved,

sudo apt-get install -y postgis postgresql-9.3-postgis-2.1
pip install psycopg2

or

sudo apt-get install libpq-dev python-dev
pip install psycopg2

回答 2

只需安装libpq-dev

$ sudo apt-get install libpq-dev

Just install libpq-dev

$ sudo apt-get install libpq-dev

回答 3

对我来说,这个简单的命令解决了这个问题:

sudo apt-get install postgresql postgresql-contrib libpq-dev python-dev

然后我可以做:

 pip install psycopg2

For me this simple command solved the problem:

sudo apt-get install postgresql postgresql-contrib libpq-dev python-dev

Then I can do:

 pip install psycopg2

回答 4

对于Python 3,我做到了:

sudo apt install python3-dev postgresql postgresql-contrib python3-psycopg2 libpq-dev

然后我能够做到:

pip3 install psycopg2

For Python 3, I did:

sudo apt install python3-dev postgresql postgresql-contrib python3-psycopg2 libpq-dev

and then I was able to do:

pip3 install psycopg2

回答 5

他们更改了psycopg2的包装。安装二进制版本为我解决了此问题。如果您想自己编译二进制文件,以上答案仍然有效。

参见http://initd.org/psycopg/docs/news.html#what-s-new-in-psycopg-2-8

默认情况下不再安装二进制软件包。必须明确使用“ psycopg2-binary”软件包。

还有http://initd.org/psycopg/docs/install.html#binary-install-from-pypi

因此,如果您不需要编译自己的二进制文件,请使用:

pip install psycopg2-binary

They changed the packaging for psycopg2. Installing the binary version fixed this issue for me. The above answers still hold up if you want to compile the binary yourself.

See http://initd.org/psycopg/docs/news.html#what-s-new-in-psycopg-2-8.

Binary packages no longer installed by default. The ‘psycopg2-binary’ package must be used explicitly.

And http://initd.org/psycopg/docs/install.html#binary-install-from-pypi

So if you don’t need to compile your own binary, use:

pip install psycopg2-binary

回答 6

您必须设置postgresql-server-dev-XY,其中XY为您的服务器版本,它将在模块上安装libpq-dev和其他服务器变量,以进行服务器端开发。就我而言

apt-get install postgresql-server-dev-9.5

读取软件包列表…完成构建依赖关系树读取状态信息…完成以下软件包已自动安装,不再需要:libmysqlclient18 mysql-common使用’apt-get autoremove’删除它们。将安装以下额外的软件包:
libpq-dev建议的软件包:postgresql-doc-10将安装以下新软件包:libpq-dev postgresql-server-dev-9.5

就你而言

sudo apt-get install postgresql-server-dev-X.Y
sudo apt-get install python-psycopg2

You must setup postgresql-server-dev-X.Y, where X.Y. your’s servers version, and it will install libpq-dev and other servers variables at modules for server side developing. In my case it was

apt-get install postgresql-server-dev-9.5

Reading package lists… Done Building dependency tree Reading state information… Done The following packages were automatically installed and are no longer required: libmysqlclient18 mysql-common Use ‘apt-get autoremove’ to remove them. The following extra packages will be installed:
libpq-dev Suggested packages: postgresql-doc-10 The following NEW packages will be installed: libpq-dev postgresql-server-dev-9.5

In your’s case

sudo apt-get install postgresql-server-dev-X.Y
sudo apt-get install python-psycopg2

回答 7

我在Ubuntu 18.04上使用了虚拟环境,并且由于我只想将其安装为客户端,所以我只需要这样做:

sudo apt install libpq-dev
pip install psycopg2

并安装没有问题。当然,您可以像其他答案一样使用二进制文件,但是我更喜欢这种解决方案,因为它是在requirements.txt文件中声明的。

I was using a virtual environment on Ubuntu 18.04, and since I only wanted to install it as a client, I only had to do:

sudo apt install libpq-dev
pip install psycopg2

And installed without problems. Of course, you can use the binary as other answers said, but I preferred this solution since it was stated in a requirements.txt file.


声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。