在Ubuntu 20.04中安装libpq-dev的问题

问题描述

我当前正在尝试安装libpq-dev来安装psycopg2。问题是,当我尝试安装它时,发生错误提示我没有最新的libpq5版本。但是,当我尝试下载libpq5的较新版本时,系统提示我已经具有最新版本。错误的例子。

lhmendes@lhmendes-GA-78LMT-S2P:~$ sudo apt-get install libpq-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages Could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libpq-dev : Depends: libpq5 (= 12.4-0ubuntu0.20.04.1) but 12.4-1.pgdg20.04+1 is to be installed
E: Unable to correct problems,you have held broken packages.
lhmendes@lhmendes-GA-78LMT-S2P:~$ sudo apt-get install libpq5
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libpq5 is already the newest version (12.4-1.pgdg20.04+1).
0 upgraded,0 newly installed,0 to remove and 4 not upgraded.

解决方法

这对我有用:

sudo apt-get install libpq5=12.7-0ubuntu0.20.04.1
,

我想说您已经安装了最新的libpq12.4-1),但是libpq-dev需要较旧的版本(12.4-0),这会造成问题。

您可以尝试安装较旧的libpq

 apt-get install libpq==12.4-0ubuntu0.20.04.1

但是如果其他程序使用最新版本,则较旧的版本可能会使该程序出现问题。

pgdg20中的

12.4-1.pgdg20.04+1表示它不是标准ubuntu仓库中的模块,而是其他仓库中的模块-可能是postgresql仓库中的模块-也许此仓库也具有最新版本libpq-dev。您将在Google中搜索12.4-1.pgdg20.04+1,也许还可以通过libpg-dev

找到12.4-1.pgdg20.04+1

我找到了libpq-dev 12.4-1.pgdg20.04+1,您可以下载.deb文件并进行安装。

或者您可以添加此postgresql repo并使用apt-get安装。此方法还将通知更新,然后您可以自动安装更新。

,

任何更高版本的libpq5都可能导致此错误。就我而言,它是libpq5 = 13.1-1.pgdg20.04 + 1。 这是与furus给出的类似答案,但更改是在Ubuntu 20.04中是libpq5(在我的情况下是这样)。 我通过安装解决了该问题

String content = parser.nextText();

然后再次安装liqpq-dev

sudo apt-get install libpq5=12.5-0ubuntu0.20.04.1
,

我必须下载 this package 并运行

sudo dpkg -i ~/Downloads/libpq-dev_13.3-1.pgdg20.04+1_amd64.deb