8

I am trying to install libpq-dev as postgres requires it, but I only get an error.

pip install libpq-dev==9.4.3

Could not find a version that satisfies the requirement libpq-dev==9.4.3 (from versions: )
No matching distribution found for libpq-dev==9.4.3
seoful
  • 91
  • 1
  • 1
  • 2
  • 2
    It is not a Python package and should be installed with your system's package manager (`apt`, `yum`‚ `dnf` etc) – hoefling Apr 06 '20 at 07:00

3 Answers3

9

Not a python package, use this instead

sudo apt-get install libpq-dev
Ayush Pallav
  • 919
  • 9
  • 18
1

If you need libpq-dev to compile psycopg2 my advice is to use precompiled wheels from psycopg2-binary. Try

pip install psycopg2-binary
phd
  • 82,685
  • 13
  • 120
  • 165
  • 2
    documentation advises to build from source though: https://www.psycopg.org/docs/install.html – DZet May 10 '21 at 16:43
  • @DZet Well, no, it currently recommends `pip install psycopg2-binary` – phd May 08 '23 at 19:19
0

I assume OP's question about libpq stemmed from them needed it for psycopg2. From Postgres' documentation,

libpq is the C application programmer's interface to PostgreSQL. libpq is a set of library functions that allow client programs to pass queries to the PostgreSQL backend server and to receive the results of these queries. libpq is also the underlying engine for several other PostgreSQL application interfaces, including those written for C++, Perl, Python, Tcl and ECPG. So some aspects of libpq's behavior will be important to you if you use one of those packages.

A platform independent solution is to use Anaconda's distribution of Python. If you use Anaconda's Python distribution and you are trying to install psycopg2, then libpq will automatically be installed for you as it's listed as a requirement. Simply run the command,

conda install psycopg2

You will see the following output

(dummy) jon@MacBook-Pro % conda install psycopg2
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

environment location: /Users/jon/miniconda3/envs/dummy

added / updated specs:
  - psycopg2


The following packages will be downloaded:

  package                    |            build
  ---------------------------|-----------------
  psycopg2-2.8.6             |   py39hbcfaee0_1         141 KB
  ------------------------------------------------------------
                                        Total:         141 KB

The following NEW packages will be INSTALLED:

krb5               pkgs/main/osx-64::krb5-1.19.2-hcd88c3b_0
libedit            pkgs/main/osx-64::libedit-3.1.20210714-h9ed2024_0
libpq              pkgs/main/osx-64::libpq-12.2-h1b4eb34_1
psycopg2           pkgs/main/osx-64::psycopg2-2.8.6-py39hbcfaee0_1


Proceed ([y]/n)? 

libpq will be in the list of items installed along with psycopg2. Thus you should not have any dependency issues when trying to use psycopg2.

Jon
  • 2,373
  • 1
  • 26
  • 34