pg_config executable not found
Asked Answered
R

55

1502

I am having trouble installing psycopg2. I get the following error when I try to pip install psycopg2:

Error: pg_config executable not found.

Please add the directory containing pg_config to the PATH

or specify the full executable path with the option:



    python setup.py build_ext --pg-config /path/to/pg_config build ...



or with the pg_config option in 'setup.cfg'.

----------------------------------------
Command python setup.py egg_info failed with error code 1 in /tmp/pip-build/psycopg2

But the problem is pg_config is actually in my PATH; it runs without any problem:

$ which pg_config
/usr/pgsql-9.1/bin/pg_config

I tried adding the pg_config path to the setup.cfg file and building it using the source files I downloaded from their website (http://initd.org/psycopg/) and I get the following error message!

Error: Unable to find 'pg_config' file in '/usr/pgsql-9.1/bin/'

But it is actually THERE!!!

I am baffled by these errors. Can anyone help please?

By the way, I sudo all the commands. Also I am on RHEL 5.5.

Repertory answered 23/7, 2012 at 19:9 Comment(3)
When you run commands as sudo, $PATH is changed. Can you please double check your $PATH as root?Tricotine
In my case, i run ln -s /usr/pgsql-9.1/bin/pg_config /usr/sbin/pg_config and every thing ok!Phenacite
I got this error too when i was trying to install to pip3 install psycopg2. So i run brew install postgresql first the run pip3 install psycopg2Mcclellan
T
1418

pg_config is in postgresql-devel (libpq-dev in Debian/Ubuntu, libpq-devel on Centos/Fedora/Cygwin/Babun.)

Thetisa answered 20/8, 2012 at 11:51 Comment(24)
Solved after installing libpq-dev on ubuntu lucid(10.04). Thank You in Advance.Cheviot
# pg_config The program 'pg_config' is currently not installed. You can install it by typing: apt-get install libpq-devPrecision
pg_config of postgress.app is at /Applications/Postgres.app/Contents/Versions/<your version>/bin (Mac OS X)Tamarin
and for windows its in `ProgramFiles\PostgreSQL\version\bin`Rupert
It's libpqxx-devel on fedora.Electrician
sudo apt-get install libpq-dev worked for me on UbuntuSyncytium
on Mac OS X: 'brew install postgresql'Headsman
on Alpine Linux: apk add postgresql-devClisthenes
@Electrician libpqxx-devel seems unrelated. xx signifies C++. The package you are looking for is postgresqlXX-devel, where XX is the version number.Sadness
It may also be here on OSX, if you use the Enterprise installer: /Library/PostgreSQL/{VERSION}/binTayyebeb
Awesome it worked after installing sudo apt-get install libpq-dev in ubuntu Thanks :)Siltstone
Same for openSUSE: zypper in postgresql-develWarrantee
Solved for me on OSX Mojave using brew install postgresqlMeeting
I had to install libpd5-devel on centos 7Bartlett
ArchLinux: extra/postgresql-libsCyclometer
On armbian which is based on debian apt install libpq-dev worked without issues. Thanks!Lezley
AWS Elastic Beanstalk with Amazon Linux 2: yum -y install postgresql-develDeficit
On CentOS pg_config can be in the postgresql/postgresql<version> packages. And for pip to be able to see it, in some cases (/usr/pgsql-<version>/bin/pg_config) it must be e.g. added to PATH. Although in the recent versions (pg >= 12) pgdg seems to have started shipping pg_config in libpq5-devel as well, in which case it's at /usr/bin/pg_config.Belt
Solved with sudo apt install libpq-dev on Ubuntu 20.04.1 LTSRainbow
I installed postgresql13-devel in the CentOS 7.9 but still show this error. must I install postgresql-devel? @ThetisaTiresias
For both fedora 35 and 36, sudo dnf install libpq-devel installed some packages but didn't work. Running sudo dnf install libpq5-devel afterwards is what worked.Equalize
Thank you @BillCheatham. This command worked for me too: sudo apt-get install libpq-devTick
I am using amazon-linux and installing postgresql-devel fixed this issue for me.Arsenopyrite
This sort of ruines the idea behind virtualenv if one tries to setup a contained environment for PostgirSQL development using Python. I guess for people, who would to have such an environment, Anaconda/Miniconda would be a better option.Magnitogorsk
S
813

On Mac OS X, I solved it using the homebrew package manager

brew install postgresql
Sequacious answered 9/7, 2014 at 4:28 Comment(11)
Excellent! This solved the problem for me, but newbies should be aware that you need to install the Homebrew package manager first in order for the brew command to work.Seoul
Worked for me also, even though I did the brew install after the pgadmin install.Carom
Doesn't that install the entire database?Enfilade
@Enfilade Yes, it will. Instead of installing postgresql and setting up paths, symlinks, etc manually, I would recommend using a package manager such as homebrew.Sequacious
I need the extra brew link postgresqlAchelous
To add to @seane's comment, use this walkthrough to install homebrew.Outbreed
This was what worked for me, thank you a lot. It is important to note that there is indeed an important connection between psycopg2 and postgresql that I was not aware of before this.Lagoon
Worked for me! (Mac OS) -- needed to add the following in my .zshrc --> export PATH=$HOME/bin:/usr/local/bin:$PATHBackflow
This is still working to this day. Thanks a bunch ! Cheers !Agripina
I did not need to do the extra brew link. Installed postgresql@14.Gifted
For Apple silicon (e.g., M1, M2) use: arch -arm64 brew install postgresql, see: https://mcmap.net/q/24265/-error-cannot-install-under-rosetta-2-in-arm-default-prefix-opt-homebrewEnvoi
I
393

Have you installed python-dev? If you already have, try also installing libpq-dev

sudo apt-get install libpq-dev python-dev

From the article: How to install psycopg2 under virtualenv

Indevout answered 20/1, 2013 at 11:51 Comment(9)
In my computer,I only install the client of Postgresql,So that you must install the libpq-dev and the python-dev.Charolettecharon
Doubtful that python-dev is needed.Puerilism
python3-dev is needed. Without it I get Python.h: No such file or directoryLowerclassman
one more dependency required for this is apt-get install -y gccDrubbing
I had python3-dev installed but had the same error until I installed libpq-dev, thanks!Preiser
if you are using python2.7 install python-dev, if you are using python3.5 python3.5-dev, and so on for other versions of python. For me it was python3.9-dev.Rayshell
After upgrading to python 3.9 I have to execute: sudo apt install python3.9-devReeducate
on Linux Mint 20.2 Cinnamon I did sudo apt-get install libpq-dev python-dev sudo apt get install python3-dev and it worked. thanks!Affairs
This command gives me this error: libpq-dev : Depends: libpq5 (= 12.11-0ubuntu0.20.04.1) but 14.3-1.pgdg20.04+1 is to be installedMarbling
B
127

Also on OSX. Installed Postgress.app from http://postgresapp.com/ but had the same issue.

I found pg_config in that app's contents and added the dir to $PATH.

It was at /Applications/Postgres.app/Contents/Versions/latest/bin. So this worked: export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH".

Benny answered 10/7, 2014 at 19:26 Comment(3)
@GianlucaLodigiani you can also do this if you dont want to restart the console PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH" pip install psycopg2Daughter
Perfect BigSur Apple Silicon Works like a charm. I did add the same to ~/.zshrc so that its always available for me.Outfight
worked on Mac Monterey.Ssm
V
116

You can install pre-compiled binaries on any platform with pip or conda:

python -m pip install psycopg2-binary

or

conda install psycopg2

Please be advised that the psycopg2-binary pypi page recommends building from source in production:

The binary package is a practical choice for development and testing but in production it is advised to use the package built from sources

To use the package built from sources, use python -m pip install psycopg2. That process will require several dependencies (documentation) (emphasis mine):

  • A C compiler.
  • The Python header files. They are usually installed in a package such as python-dev. A message such as error: Python.h: No such file or directory is an indication that the Python headers are missing.
  • The libpq header files. They are usually installed in a package such as libpq-dev. If you get an error: libpq-fe.h: No such file or directory you are missing them.
  • The pg_config program: it is usually installed by the libpq-dev package but sometimes it is not in a PATH directory. Having it in the PATH greatly streamlines the installation, so try running pg_config --version: if it returns an error or an unexpected version number then locate the directory containing the pg_config shipped with the right libpq version (usually /usr/lib/postgresql/X.Y/bin/) and add it to the PATH:
$ export PATH=/usr/lib/postgresql/X.Y/bin/:$PATH

You only need pg_config to compile psycopg2, not for its regular usage.

Once everything is in place it’s just a matter of running the standard:

$ pip install psycopg2

or, from the directory containing the source code:

$ python setup.py build
$ python setup.py install
Valene answered 21/11, 2019 at 21:28 Comment(4)
On Ubuntu, I needed to install the libpq-dev library first and then just run the pip install command again: apt install libpq-devTherefrom
That solved it on a Mac OS X without needing to install postgresql altogetherGerstein
Thank you for pointing out the documentation's recommendation to build from source. I second this suggestion--devs should use the later half of this answer and avoid the pre-packaged binary, even for most development purposes.Hightoned
This works for elastic beanstalkDactylography
S
89

For ubuntu users, this is the solution:

sudo apt install libpq-dev

It worked for me.

Standush answered 4/10, 2021 at 18:12 Comment(3)
And on Arch/Manjaro it is postgresql-libsNinetta
it wokred for me too. whats the problem here? what is libpq-dev used for?Uninspired
@Uninspired when pip builds the psycopg2 module, it requires libpq-dev to do so. There are probably libraries which psychopg2 depends on -- such as a class for handling connections, perhaps.Orthopteran
I
57

On alpine, the library containing pg_config is postgresql-dev. To install, run:

apk add postgresql-dev
Irony answered 6/7, 2017 at 1:16 Comment(0)
B
53

This is what worked for me on CentOS, first install:

sudo yum install postgresql postgresql-devel python-devel

On Ubuntu just use the equivilent apt-get packages.

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

And now include the path to your postgresql binary dir with you pip install, this should work for either Debain or RHEL based Linux:

sudo PATH=$PATH:/usr/pgsql-9.3/bin/ pip install psycopg2

Make sure to include the correct path. Thats all :)

Bestrew answered 20/11, 2014 at 15:16 Comment(3)
On Ubuntu it's sudo apt-get install postgresql postgresql-dev python-dev, and this worked for me.Finlay
also works on Amazon Linux AMI as of Dec 2016. Also make sure gcc is installed and python3-devel.Candidacandidacy
On Amazon Linux the first command worked nice.Marbling
D
45

You have to install libpq-dev/postgresql-libs, which is the header files and static library for compiling C programs to link with the libpq library in order to communicate with a PostgreSQL database backend.

On Arch this will run:

$ sudo pacman -S postgresql-libs

On Debian and Ubuntu:

$ sudo apt-get install libpq-dev

On Mac OS X:

$ brew install postgresql

On Red Hat/CentOS/Fedora:

$ sudo yum install postgresql-devel
Decane answered 9/1, 2021 at 22:27 Comment(1)
Upvoted for helpfully explaining the precise cause of the issue.Borneol
P
39

I had this issue because I didn't had a postgres install. If you have brew install run

brew install postgresql

This should fix the issue.

Pickerel answered 23/7, 2021 at 15:3 Comment(1)
yes, I was updating the django requirement.txt. I was getting above error. It get solved when I installed arch -arm64 brew install postgresql for M1 macAdda
G
37
apt-get build-dep python-psycopg2
Gorton answered 8/2, 2013 at 19:4 Comment(0)
G
36

Just to sum up, I also faced exactly same problem. After reading a lot of stackoverflow posts and online blogs, the final solution which worked for me is this:

  1. PostgreSQL(development or any stable version) should be installed before installing psycopg2.

  2. The pg_config file (this file normally resides in the bin folder of the PostgreSQL installation folder) PATH had to be explicitly setup before installing psycopg2. In my case, the installation PATH for PostgreSQL is:

    /opt/local/lib/postgresql91/

so in order to explicitly set the PATH of pg_config file, I entered following command in my terminal:

PATH=$PATH:/opt/local/lib/postgresql91/bin/

This command ensures that when you try to pip install psycopg2, it would find the PATH to pg_config automatically this time.

I have also posted a full error with trace and its solution on my blog which you may want to refer. Its for Mac OS X but the pg_config PATH problem is generic and applicable to Linux also.

Grub answered 5/7, 2013 at 6:46 Comment(2)
for me on OS X the path looked like this PATH="/Applications/Postgres.app/Contents/Versions/9.3/bin:$PATH"Pazice
@andi Yea, the installation path of Postgres may differ but the installation recipe for psycopg2 which I mentioned above remains the same. Hope it helped.Grub
A
36

You should add python requirements used in Postgres on Ubuntu. Run:

sudo apt-get install libpq-dev python-dev
Accidence answered 8/9, 2017 at 6:54 Comment(0)
A
32

sudo apt-get install libpq-dev works for me on Ubuntu 15.4

Athanasius answered 7/12, 2016 at 22:34 Comment(1)
If you use newer Ubuntu, still use aforementioned installation instruction. See pg_configBurglar
G
25

On Linux Mint sudo apt-get install libpq-dev worked for me.

Gladdie answered 18/12, 2017 at 2:13 Comment(0)
L
24

For those running OS X, this solution worked for me:

  1. Install Postgres.app:

http://www.postgresql.org/download/macosx/

  1. Then open the Terminal and run this command, replacing where it says {{version}} with the Postgres version number:
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/{{version}}/bin

e.g.

export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin
Linville answered 26/3, 2015 at 11:11 Comment(2)
Or symlink it to the latest version sudo ln -s /Applications/Postgres.app/Contents/Versions/latest/bin/pg_config /usr/local/bin/pg_configRadiotelephony
On my Mac, I exported the PATH from ~/.zprofile file.Shivers
C
24

Simply run the following:

sudo apt install libpq-dev

Fixed the issue for me

Colleencollege answered 11/2, 2021 at 9:2 Comment(0)
C
22

UPDATE /etc/yum.repos.d/CentOS-Base.repo, [base] and [updates] sections
ADD exclude=postgresql*

curl -O http://yum.postgresql.org/9.1/redhat/rhel-6-i386/pgdg-centos91-9.1-4.noarch.rpmr  
rpm -ivh pgdg-centos91-9.1-4.noarch.rpm

yum install postgresql  
yum install postgresql-devel

PATH=$PATH:/usr/pgsql-9.1/bin/

pip install psycopg2
Caecum answered 3/9, 2013 at 10:4 Comment(0)
M
19

Try to add it to PATH:

PATH=$PATH:/usr/pgsql-9.1/bin/ ./pip install psycopg2
Mancuso answered 20/8, 2012 at 12:16 Comment(4)
-bash: cd: /usr/pgsql-x.x/bin/: No such file or directoryCheviot
@pylover, you need to use correct path to you Postgres bin directory. Are you sure that /usr/pgsql-x.x/bin/ is correct?Mancuso
It would also be sufficient just to add the folder where all important pg_ files live. For postgres.app this path on Mac OS X is /Applications/Postgres.app/Contents/Versions/9.3/bin. PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin Please update your version* if a new version got released!Tamarin
This worked for me on OS X El Capitan: PATH=$PATH:/usr/local/Cellar/postgresql/9.5.0/bin/Griffith
H
18

Ali's solution worked for me but I was having trouble finding the bin folder location. A quick way to find the path on Mac OS X is to open psql (there's a quick link in the top menu bar). This will open a separate terminal window and on the second line the path of your Postgres installation will appear like so:

My-MacBook-Pro:~ Me$ /Applications/Postgres93.app/Contents/MacOS/bin/psql ; exit;

Your pg_config file is in that bin folder. Therefore, before installing psycopg2 set the path of the pg_config file:

PATH=$PATH:/Applications/Postgres93.app/Contents/MacOS/bin/

or for newer version:

PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin

Then install psycopg2.

Hudibrastic answered 31/12, 2013 at 16:45 Comment(2)
Newer docs use the following path: /Applications/Postgres.app/Contents/Versions/9.3/binRawson
It does seem to move about. find /usr/local -name 'pg_config'Tangy
B
17

I'm going to leave this here for the next unfortunate soul who can't get around this problem despite all the provided solutions. Simply use sudo pip3 install psycopg2-binary

Bigamist answered 27/9, 2019 at 10:50 Comment(3)
This didn't work for me. Only brew install postgresql fixed it.Anglican
You might have to pip install psycopg2-binary for me: pip -> python2, pip3 -> python3. But so long as you got it working, it was one of many solutions!Bigamist
Solved my problem when using docker.Gulf
T
16

You need to upgrade your pip before installing psycopg2. Use this command

pip install --upgrade pip
Thessalonian answered 10/3, 2017 at 8:17 Comment(2)
A more detailed answer could be helpful in most cases.Orthotropic
this is the solution for me. followed by pip install psycopg2-binary. ThxWether
R
14

On MacOS, the simplest solution will be to symlink the correct binary, that is under the Postgres package.

sudo ln -s /Applications/Postgres.app/Contents/Versions/latest/bin/pg_config /usr/local/bin/pg_config

This is fairly harmless, and all the applications will be able to use it system wide, if required.

Radiotelephony answered 4/8, 2019 at 6:59 Comment(3)
Works for me, did not have to sudo though. Thank you!Royo
Works for me indeed!Smalley
On macOS 11.01, M1 Chip, creating a symlink worked for me: sudo ln -s /Library/PostgreSQL/13/bin/pg_config /usr/local/bin/pg_configAncalin
P
12

On Mac OS X and If you are using Postgres App (http://postgresapp.com/):

export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin

No need to specify version of Postgres in this command. It will be always pointed to latest.

and do

pip install psycopg2

P.S: If Changes doesn't reflect you may need to restart the Terminal/Command prompt

Source

Peptize answered 26/10, 2016 at 6:41 Comment(0)
U
11

Installing python-psycopg2 solved it for me on Arch Linux:

pacman -S python-psycopg2
Uncut answered 28/10, 2016 at 9:7 Comment(2)
What about Windows?Coronado
@PrathameshMore I don't know, I don't use Windows. Have you tried this answer: https://mcmap.net/q/24261/-pg_config-executable-not-found ?Uncut
S
10

The following is only relevant for psycopg2 <= 2.6.2

On Windows, You may want to install the Windows port of Psycopg, which is recommended in psycopg's documentation.

Sequacious answered 10/9, 2014 at 14:15 Comment(2)
These links do not work anymore.Cinchonism
The Windows port link is visibly broken (the website seems down).Eleazar
H
10

Just solved the problem in Cent OS 7 by:

export PATH=$PATH:/usr/pgsql-9.5/bin

make sure your PostgreSql version matches the right version above.

Hype answered 17/4, 2016 at 18:44 Comment(0)
E
10

To those on macOS Catalina using the zsh shell who have also installed the postgres app:

Open your ~/.zshrc file, and add the following line:

export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"

Then close all your terminals, reopen them, and you'll have resolved your problem.

If you don't want to close your terminals, simply enter source ~/.zshrc in whatever terminal you'd like to keep working on.

Etch answered 27/11, 2019 at 0:15 Comment(1)
this works on big sur too.Anarthria
L
9

This was partly suggested before, adding it here for clarity.

From the documentation at https://www.psycopg.org/docs/install.html.
they suggest running: $ pip install psycopg2-binary

That solved the issue for me.

Loaiasis answered 24/9, 2020 at 8:33 Comment(1)
This should not be used in a production environmentDescendible
H
8

Here, for OS X completeness: if you install PostgreSQL from MacPorts, pg_config will be in /opt/local/lib/postgresql94/bin/pg_config.

When you installed MacPorts, it already added /opt/local/bin to your PATH.

So, this will fix the problem: $ sudo ln -s /opt/local/lib/postgresql94/bin/pg_config /opt/local/bin/pg_config

Now pip install psycopg2 will be able to run pg_config without issues.

Humming answered 29/4, 2015 at 18:36 Comment(1)
Thank you for providing a MacPorts-specific answer! 🙏🏻 I could not find one, and this worked for me.Miltie
A
8

run the following command to resolve pg_config executable not found:-

sudo apt-get install --reinstall libpq-dev
Ajay answered 24/1, 2021 at 17:16 Comment(0)
C
7

There is a lack of answers for windows users. Here is how I solved this issue.

First add the PostgreSQL bin folder into the path variable like this

set PATH=%PATH%;C:\Program Files\PostgreSQL\11\bin

Substitute \11\ with your version of Postgres

next run

pip install pyscopg2

this at least got me to a compiling error.

Update: it looks to be an issue with the psycopg2 library and it’s dependencies not playing nice with python 3.8. https://github.com/psycopg/psycopg2/issues/990

Challenge answered 17/10, 2019 at 20:53 Comment(0)
G
7

For mac users, extend your path variable to include PostgreSQL like this export PATH=$PATH:/Library/PostgreSQL/12/bin.

Gull answered 1/3, 2020 at 14:14 Comment(0)
D
7

I recommend that you try to use Postgres.app. (http://postgresapp.com) This way you can easily turn Postgres on and off on your Mac. Once you do, add the path to Postgres to your .profile file by appending the following:

PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"

Only after you added Postgres to your path you can try to install psycopg2 either within a virtual environment (using pip) or into your global site-packages.

Delectable answered 29/4, 2020 at 15:29 Comment(0)
C
6

sudo yum install postgresql-devel (centos6X)

pip install psycopg2==2.5.2

Cudweed answered 8/4, 2014 at 8:0 Comment(0)
F
6

For those who don't have Postgresql locally installed and wish to run it as a Docker container. You should use psycopg2-binary.

Fukien answered 4/9, 2022 at 17:55 Comment(0)
C
5

a simple solution can be

pip install psycopg2==2.7.5
Carrolcarroll answered 2/2, 2020 at 8:21 Comment(0)
E
5

If you're trying to add a psycopg2 dependency in your virtual environment that will allow your python project to connect to your docker or kubernetes pod that's running postgresql separately, on your Mac and are not really interested in installing postgresql on your Mac just so that you can get pg_config, here's what you do instead:

Install psycopg2_binary as suggested in the error output from the pipenv install and everything will work out just fine.

Elf answered 28/7, 2020 at 19:32 Comment(0)
A
4

I am pretty sure you've experienced the same "problem" i did, therefore I'll offer you the extremely easy solution...

In your case, the actual path that you need to add to $PATH (or as a command param) is:

/usr/pgsql-9.1/bin/pg_config

not

/usr/pgsql-9.1/bin

E.g. if you run the python setup.py script afterwards, you would run it like this:

python setup.py build_ext --pg-config /usr/pgsql-9.1/bin/pg_config build

Probably too late, but still the easiest solution.

LATER EDIT:

Under further test I found out that if you initially add the path to pg_config in the form

/usr/pgsql-9.1/bin

(without /pg_config after ...../bin) and run the pip install command it will work.

However, if you then decide to follow the indication to run python setup.py, you will have to specify the path with /pg_config after ...../bin, i.e.

python setup.py build_ext --pg-config /usr/pgsql-9.1/bin/pg_config build
Almanac answered 30/1, 2014 at 12:16 Comment(1)
An alternative to adding the pgsql/bin directory to the PATH that I've used a fair bit is to symlink /usr/pgsql-9.6/bin/pg_config (or whatever it's called on your system) to /usr/bin/pg_config - that way it's available in the PATH you've already got.Wisdom
C
4

This is how I managed to install psycopg2

$ wget http://initd.org/psycopg/tarballs/PSYCOPG-2-5/psycopg2-2.5.3.tar.gz
$ tar -xzf psycopg2-2.5.3.tar.gz
$ cd psycopg2-2.5.3
$ pip install .
Chemosphere answered 7/8, 2014 at 2:59 Comment(0)
R
4

Using postgresql-devel for redhat/ fedora series resolved the issue.

yum install postgresql-devel

Reverberatory answered 26/5, 2022 at 12:26 Comment(0)
D
4
apt install python3-pip -y
apt install python3.10-venv -y
apt install postgresql -y
apt install libpq-dev python2-dev python2 python-dev-is-python3 -y
Dionedionis answered 20/4, 2023 at 1:25 Comment(2)
The question was posed by a Redhat user. The suggested commands only work on Debian/Ubuntu.Pahari
Installing postgresql is not necessary, just with libpq-dev is enough.Josephinajosephine
T
3

for CentOS/RedHat make sure that /etc/alternatives/pgsql-pg_config is a non-broken symlink

Trescott answered 20/9, 2017 at 11:21 Comment(0)
F
3

For MAC users -

After adding the postgresql package through HomeBrew, you might have to add the openssl path variable -

export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/

Then you can again pip install the psycopg2 package which should work.

Faithfaithful answered 20/12, 2020 at 11:46 Comment(0)
M
3

if you have recently updated python or changed default python (let's say from 3.6 to 3.8). The following code

sudo apt-get install python-dev   OR    sudo apt-get install python3-dev

will be installing/working for the previous python version.

so if you want this command to work for the recently updated/changed python version try mentioning that specific version like python3.8 in command like

sudo apt-get install python3.8-dev  

try above with following

pip install wheel
export PATH=/path/to/compiled/postgresql/bin:"$PATH"
sudo apt-get install libpq-dev
sudo apt-get install python3.x-dev    **Change x with your version, eg python3.8**
pip install psycopg2-binary
pip install psycopg2
Muskogee answered 26/12, 2020 at 6:40 Comment(1)
turning the line from psycopg2 to psycopg2-binary seem worked for meKnar
L
3

I have really big issue with installation of this library on Oracle Linux 7.9. And whatever I was doing I wasn't able to install psycopg2 via pip. So I decide to install it via yum with this command:

yum install http://mirror.centos.org/centos/7/os/x86_64/Packages/python-psycopg2-2.5.1-4.el7.x86_64.rpm

With this command the psycopg2 was installed and I was able create postgres user, DB via ansible. (I know this is like sixtieth answer but I hope this answer can still help somebody).

Lovash answered 15/10, 2021 at 11:53 Comment(0)
A
2

On Gentoo You have to execute the following

# Install postgresql client libraries
sudo emerge postgresql-base
Abate answered 4/9, 2014 at 12:16 Comment(1)
For me, the issue was that the links that eselect postgresql set [...] creates were only partially created / broken. I rmed the ones that looked related (see ls /usr/include/*p*g* and *p*q*) and then recreated them with eselect postgresql set 9.5.Yacano
H
2

For anyone experiencing this issue working on a Django application and deploying to AWS, the method described in this tutorial worked for me: https://realpython.com/deploying-a-django-app-and-postgresql-to-aws-elastic-beanstalk/

Here is the author's explanation for when you get the following error:

Error: pg_config executable not found.

The problem is that we tried to install psycopy2 (the Postgres Python bindings), but we need the Postgres client drivers to be installed as well. Since they are not installed by default, we need to install them first.

eb will read custom .config files from a folder called “.ebextensions” at the root level of your project. These .config files allow you to install packages, run arbitrary commands and/or set environment variables. Files in the “.ebextensions” directory should conform to either JSON or YAML syntax and are executed in alphabetical order.

The first thing to do is install some packages so that our pip install command will complete successfully. To do this, let’s create a file called .ebextensions/01_packages.config:

packages:
  yum:
    git: []
    postgresql93-devel: []
    libjpeg-turbo-devel: []

EC2 instances run Amazon Linux, which is a Redhat flavor, so we can use yum to install the packages that we need. For now, we are just going to install three packages - git, the Postgres client, and libjpeg for Pillow.

Harrus answered 27/8, 2019 at 20:45 Comment(0)
S
2

The following steps solved the issue for me (ubuntu 18.04)

  1. install postgres (refer this if not installed)
  2. install libpq-dev

sudo apt-get install libpq-dev

Scholarship answered 19/4, 2021 at 8:52 Comment(0)
W
2

For Mac people with bash shell:

$ nano ~/.bash_profile
export PATH="/Library/PostgreSQL/<version>/bin:$PATH" >> at the end of the file >> save and exit source ~/.bash_profile >> to refresh the changes for the terminal to use

Wallaby answered 19/4, 2023 at 2:14 Comment(0)
C
1

I found that this page provided the best instructions for installing PostgreSQL on my mac and that the pip install command worked perfectly afterwards:

https://www.codefellows.org/blog/three-battle-tested-ways-to-install-postgresql

Cullum answered 6/1, 2015 at 9:55 Comment(0)
U
1

I got fixed this by running the following command.

env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip install psycopg2

Reference : https://mcmap.net/q/24266/-can-39-t-install-psycopg2-package-through-pip-install-on-macos

Uniformity answered 9/12, 2019 at 1:52 Comment(0)
J
1

For users that face this problem building Docker instance.

FROM python:3.9.17-slim-bullseye

RUN  apt-get update
RUN apt-get install git libpq-dev -y

COPY requirements.txt /srv/
RUN pip3 install --no-cache-dir -r /srv/requirements.txt

RUN rm -r /srv/
COPY . /srv/

if you have psycopg2==2.7.2

Josephinajosephine answered 30/6, 2023 at 9:26 Comment(0)
P
0

If you are using mac then make sure you have installed Postgresql in your machine.

Pandora answered 3/3, 2020 at 8:0 Comment(0)
C
0

You can use the binary instead, I ran into the issue in dockerizing the application when Django tried to install it as part of its dependencies, to resolve that, I used this setup for requirements.txt where the binary is installed first and then django does not try to install it again: psycopg2-binary django gunicorn

Convivial answered 23/7, 2020 at 17:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.