Problems instaling libpq-dev in ubuntu 20.04
Asked Answered
P

15

43

I am currently trying to install libpq-dev to install psycopg2. The problem is, when I try to install it, an error occurs saying I don't have the latest libpq5 version. However when I try to download the newer version of libpq5 the system says that I already have the latest version. An example of the error.

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.
Pleasure answered 7/9, 2020 at 23:48 Comment(3)
I would say you have installed latest libpq (12.4-1) but libpq-dev needs older version (12.4-0) and this makes problem. You may try to install older libpq - apt-get install libpq==12.4-0ubuntu0.20.04.1 but if other program uses the latest version then older version can make problem. Strange is pgdg20 in 12.4-1.pgdg20.04+1 because it is not module from standard ubuntu repo but from some other repo - and maybe this repo has also latest version libpq-dev. You would search 12.4-1.pgdg20.04+1 in Google and maybe you find also libpg-dev with 12.4-1.pgdg20.04+1Heartwhole
I found libpq-dev 12.4-1.pgdg20.04+1 and you can download .deb file and install it. OR you can add postgresql repo and install with apt-getHeartwhole
Hi! Tried installing libpq-dev 12.4-1.pgdg20.04+1 from the .deb but the same error occurred. Saying that i do not have some of the dependencies needed. EDIT: the link was sending to the page to download libpq-dev 12.4-1.pgdg18.04+1. Just downloaded the 20.04 one and worked! Thanks a lot!Pleasure
H
15

I would say you have installed the latest libpq (12.4-1) but libpq-dev needs older version (12.4-0) and this makes problem.

You may try to install older libpq

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

but if other program uses the latest version then older version can make problem with this program.

pgdg20 in 12.4-1.pgdg20.04+1 means it is not module from standard ubuntu repo but from some other repo - probably postgresql repo - and maybe this repo has also the latest version libpq-dev. You would search 12.4-1.pgdg20.04+1 in Google and maybe you could find also libpg-dev with 12.4-1.pgdg20.04+1


I found libpq-dev 12.4-1.pgdg20.04+1 and you can download .deb file and install it.

Or you can add this postgresql repo and install with apt-get. This method will also inform about updates and then you could install updates automatically.

Heartwhole answered 8/9, 2020 at 0:24 Comment(0)
M
57

As of May 2023 the command is:

sudo apt-get install libpq5=12.12-0ubuntu0.20.04.1 && sudo apt-get install libpq-dev

When you're using Ubuntu 22.04 try:

sudo apt-get install libpq5=14.5-0ubuntu0.22.04.1 && sudo apt-get install libpq-dev
Martres answered 26/1, 2022 at 18:40 Comment(7)
This is great! i spent whole last night to find the solution. World is cruel :( Thanks.Kellda
Confirmed to be working now too :+1: Thanks!Listen
Not working, is this version of libpq5 discontinued? Can anyone tell me if this works right now?Pentastich
what error are you getting? It still worked a couple of days ago for me.Martres
I also found it didn't work. The command is sudo apt-get install libpq5=12.9-0ubuntu0.20.04.1 && sudo apt-get install libpq-dev and the error message is E: Version '12.9-0ubuntu0.20.04.1' for 'libpq5' was not foundKolomna
Thank you for this, wasted a lot of time trying to fix this before seeing this solutionGass
I think in 90% of the cases (if not 100%) this happens because the pgadmin4 repo provides the libpq5 package but not the matching libpq-dev along with it. See github.com/pgadmin-org/pgadmin4/issues/5650Collapse
S
37

Any newer version of libpq5 can cause this error. In my case it was libpq5=13.1-1.pgdg20.04+1. It's the similar answer as furus has given but the change is it's libpq5 in ubuntu 20.04 (atleast in my case). I fixed the issue by installing

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

and then install liqpq-dev again

sudo apt-get install libpq-dev
Sanborne answered 11/12, 2020 at 2:12 Comment(2)
sudo apt-get install libpq5=12.6-0ubuntu0.20.04.1Merell
now it's: sudo apt-get install libpq5=12.9-0ubuntu0.20.04.1Martres
H
15

I would say you have installed the latest libpq (12.4-1) but libpq-dev needs older version (12.4-0) and this makes problem.

You may try to install older libpq

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

but if other program uses the latest version then older version can make problem with this program.

pgdg20 in 12.4-1.pgdg20.04+1 means it is not module from standard ubuntu repo but from some other repo - probably postgresql repo - and maybe this repo has also the latest version libpq-dev. You would search 12.4-1.pgdg20.04+1 in Google and maybe you could find also libpg-dev with 12.4-1.pgdg20.04+1


I found libpq-dev 12.4-1.pgdg20.04+1 and you can download .deb file and install it.

Or you can add this postgresql repo and install with apt-get. This method will also inform about updates and then you could install updates automatically.

Heartwhole answered 8/9, 2020 at 0:24 Comment(0)
G
7

This worked for me:

sudo apt-get install libpq5=12.7-0ubuntu0.20.04.1
Giannini answered 6/7, 2021 at 19:18 Comment(0)
S
5

if you are trying to install it on Ubuntu 20.04 then run below command to install libpq-dev

Command1: sudo apt-get install libpq5=12.2-4

Command2: sudo apt install libpq-dev

Link: https://ubuntu.pkgs.org/20.04/ubuntu-main-arm64/libpq-dev_12.2-4_arm64.deb.html

Scarab answered 12/1, 2022 at 15:49 Comment(0)
E
3

What worked in my case was.

sudo apt-get install libpq5=14.5-0ubuntu0.22.04.1

The libpq5 package that worked for me corresponds to my version of ubuntu I found it at:

https://pkgs.org/download/libpq-dev

For ubuntu version 22.04.1

Then I was able to use sudo apt-get install libpq-dev without problems.

Engeddi answered 5/9, 2022 at 2:37 Comment(1)
you just saved a lot of my time mate! +1 lolHauge
L
1

I had to download this package and run

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

Legator answered 14/7, 2021 at 8:40 Comment(0)
G
1

I have the same problem when I install psycopg2-binary, It seems like it is caused by repository conflict.

In software & Updates => other software

Unselect https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/focal.

sudo apt-get remove libpg5

sudo apt-get install libpg5 libpg-dev

Solved my problem

Gride answered 18/9, 2021 at 7:50 Comment(1)
libpq as in Q not g as in GDemimonde
P
1

This problem persists in 22.04:

Os pacotes a seguir têm dependências desencontradas:
 libpq-dev : Depende: libpq5 (= 14.3-0ubuntu0.22.04.1) mas 14.4-1.pgdg22.04+1     está para ser instalado

I had to revert libpq5 as per the error message above:

sudo apt-get install libpq5=14.3-0ubuntu0.22.04.1
Pawl answered 1/7, 2022 at 21:36 Comment(0)
A
0

I think this is because your libpg-dev is depending on libpg5=12.4-0ubuntu0.20.04.1 but 12.4-1.pgdg20.04+1 is to be installed in your machine that is why the error occurs when you sudo apt-get install libpg-dev.

Therefore you can try sudo apt-get install libpg5=12.4-0ubuntu0.20.04.1 first, after that, sudo apt-get install libpg-dev.

I did this way to solve my problem which was similar to yours.

Antiar answered 15/9, 2021 at 4:30 Comment(0)
C
0

Update package worked for me:

sudo apt update
sudo apt install libpg-dev
Carolyncarolyne answered 5/4, 2022 at 15:6 Comment(0)
T
0

You can find the latest version here. https://packages.ubuntu.com/bionic/libpq-dev

Tatary answered 19/8, 2022 at 13:1 Comment(0)
H
0

The only solution that worked for me is

sudo apt-get install libpq5=14.5-0ubuntu0.22.04.1

sudo apt-get install libpq-dev

then

pip install psycopg2

Yes, upvote when this works for you. Good luck.

Hauge answered 16/10, 2022 at 6:43 Comment(0)
C
0

This issue was fixed in pgadmin repo: it now provides a matching version of libpq-dev along with libpq5. You can update both packages to the latest version and remove pins (unless there is yet another flawed provider of the libpq5 package in your apt sources).

$ dpkg -l libpq*
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version            Architecture Description
+++-==============-==================-============-============================================
ii  libpq-dev      15.1-1.pgdg20.04+1 amd64        header files for libpq5 (PostgreSQL library)
ii  libpq5:amd64   15.1-1.pgdg20.04+1 amd64        PostgreSQL C client library
Collapse answered 3/2, 2023 at 16:21 Comment(0)
B
0

This seems to happen when you use the Postgres APT repository for PGAdmin 4 - I'm still getting this on my Ubuntu 23.10 machine. The other answers pointed me in the right direction. The trick is to look at all available packages:

apt show --all libpq-dev

This will show all installable packages, sorted in reverse version order (newest at the top). Look through the entries and pick the newest version that does not have an APT-Source entry for ftp.postgresql.org. Then take the Version string and use that to install the library:

apt install libpq-dev=15.5-0ubuntu0.23.10.1

The LDAP library appears to be referenced differently by the upstream Postgres package repository versus the official Ubuntu ones.

Boracic answered 11/1 at 19:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.