简体   繁体   English

无法在 ubuntu 18.04 上安装 psycopg2

[英]cannot install psycopg2 on ubuntu 18.04

I am trying to install python3-psycopg2 as a part of postgresql installation, but I get:我正在尝试安装python3-psycopg2作为postgresql安装的一部分,但我得到:

The following packages have unmet dependencies:
 python3-psycopg2 : Depends: python3 (>= 3.7~) but 3.6.7-1~18.04 is to be installed
E: Unable to correct problems, you have held broken packages.

I installed python3.8 and configured python3 link to it:我安装了python3.8并配置了python3链接到它:

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1

But I still get the same error.但我仍然得到同样的错误。

I have an Ubuntu 18.04 OS.我有一个Ubuntu 18.04操作系统。

The Psycopg2 library is built as a wrapper around libpq and mostly written in C. It is distributed as a sdist and is built during installation. Psycopg2库是作为libpq的包装器构建的,主要用 C 编写。它作为sdist分发并在安装期间构建。 For this reason it requires some PostgreSQL binaries and headers to be present during installation.出于这个原因,它需要在安装过程中存在一些PostgreSQL二进制文件和头文件。

Consider running these 2 commands:考虑运行以下 2 个命令:

sudo apt install python3-dev libpq-dev

The main goal of the command above is to provide all requirements for building Psycopg2 .上述命令的主要目标是提供构建Psycopg2所有要求。

Then:然后:

pip3 install psycopg2

You should have psycopg2 installed and working now.你应该已经安装了psycopg2并且现在可以工作了。

While the explanation of Gitau is very good.虽然Gitau的解释非常好。 You can simply install the psycopg2 binary instead as mentioned by Maurice:您可以简单地安装 psycopg2 二进制文件,而不是像 Maurice 提到的那样:

python3 -m pip install psycopg2-binary

or just要不就

pip install psycopg2-binary

Sometime psycopg2-binary is not a solution because other packages require for psycopg2 on their dependencies.有时 psycopg2-binary 不是解决方案,因为其他软件包需要 psycopg2 依赖它们。

As cited above, you need to install some libs on ubuntu before install psycopg2.如上所述,在安装 psycopg2 之前,您需要在 ubuntu 上安装一些库。 For me, I had to install build-essential as well.对我来说,我还必须安装 build-essential。

sudo apt install python3-dev libpq-dev build-essential

and then接着

pip install psycopg2

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

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