[python] How to find pg_config path

Complete newbie here, trying to set up Django to work with PostgreSQL.

I'm using mac osx 10.6.8. I have also installed PostgreSQL 9.3

When I run pip install psycopg2 in terminal I get the following error

Downloading/unpacking psycopg2
  Downloading psycopg2-2.5.2.tar.gz (685kB): 685kB downloaded
  Running setup.py (path:/private/var/folders/A9/A99cs6x0FNusPejCVkYNTE+++TI/-Tmp-/pip_build_bengorman/psycopg2/setup.py) egg_info for package 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'.
    Complete output from command python setup.py egg_info:
    running egg_info

creating pip-egg-info/psycopg2.egg-info

writing pip-egg-info/psycopg2.egg-info/PKG-INFO

writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt

writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt

writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'

warning: manifest_maker: standard file '-c' not found



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'.

I've seen a number of posts on this
how-to-install-psycopg2-with-pip-on-python
pg-config-executable-not-found

but I have no clue how to find the bin folder location containing pg_config. Any tips on finding this path?

This question is related to python django macos postgresql

The answer is


check /Library/PostgreSQL/9.3/bin and you should find pg_config

I.E. /Library/PostgreSQL/<version_num>/

ps: you can do the following if you deem it necessary for your pg needs -

create a .profile in your ~ directory

export PG_HOME=/Library/PostgreSQL/9.3
export PATH=$PATH:$PG_HOME/bin

You can now use psql or postgres commands from the terminal, and install psycopg2 or any other dependency without issues, plus you can always just ls $PG_HOME/bin when you feel like peeking at your pg_dir.


This is how to simply get the path of pg_config

$ which pg_config                 // prints the directory location 
/usr/bin/pg_config

Postgres.app was updated recently. Now it stores all the binaries in "Versions" folder

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

Where 9.4 – version of PostgreSQL.


path of pg_config in my case (MacOS)

/Library/PostgreSQL/13/bin

Execute the following in the terminal:

PATH="/Library/PostgreSQL/13/bin:$PATH"

Then

pip install psycopg2

sudo find / -name "pg_config" -print

The answer is /Library/PostgreSQL/9.1/bin/pg_config in my configuration (MAC Maverick)


I used :

export PATH=$PATH:/Library/PostgreSQL/9.6/bin

pip install psycopg2

Works for me by installing the first the following pip packages: libpq-dev and postgresql-common


Installing homebrew

/usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"

And then installing postgresql

brew install postgresql

gave me this lovely bit of output:

checking for pg_config... yes

ahhh yeahhhhh


Once you install the current PostgreSQL app on the MacOS X 10.11, this is where the pg_config file is /Library/PostgreSQL/9.5/bin/pg_config.

Then on the Terminal:

    $ export PG_HOME=/Library/PostgreSQL/9.5
    $ export PATH=$PATH:$PG_HOME/bin

This will put the path in the .profile of whatever terminal you are using.

In your environment (assuming you are using virtualenv) you then install psycopg2:

    $ pip install psycopg2

You should see if you had downloaded it before:

    Collecting psycopg2
      Using cached psycopg2-2.6.1.tar.gz
    Installing collected packages: psycopg2
      Running setup.py install for psycopg2 ... done
    Successfully installed psycopg2-2.6.1

To summarize -- PostgreSQL installs its files (including its binary or executable files) in different locations, depending on the version number and the installation method.

Some of the possibilities:

/usr/local/bin/
/Library/PostgreSQL/9.2/bin/
/Applications/Postgres93.app/Contents/MacOS/bin/
/Applications/Postgres.app/Contents/Versions/9.3/bin/

No wonder people get confused!

Also, if your $PATH environment variable includes a path to the directory that includes an executable file (to confirm this, use echo $PATH on the command line) then you can run which pg_config, which psql, etc. to find out where the file is located.


I had exactly the same error, but I installed postgreSQL through brew and re-run the original command and it worked perfectly :

brew install postgresql


Have same issue on mac, you probably need to

brew install postgresql

then you can run

pip install psycopg2

The brew will fix PATH issue for you

this solution works for me at least.


You can find the pg_config directory using its namesake:

$ pg_config --bindir
/usr/lib/postgresql/9.1/bin
$ 

Tested on Mac and Debian. The only wrinkle is that I can't see how to find the bindir for different versions of postgres installed on the same machine. It's fairly easy to guess though! :-)

Note: I updated my pg_config to 9.5 on Debian with:

sudo apt-get install postgresql-server-dev-9.5

Examples related to python

programming a servo thru a barometer Is there a way to view two blocks of code from the same file simultaneously in Sublime Text? python variable NameError Why my regexp for hyphenated words doesn't work? Comparing a variable with a string python not working when redirecting from bash script is it possible to add colors to python output? Get Public URL for File - Google Cloud Storage - App Engine (Python) Real time face detection OpenCV, Python xlrd.biffh.XLRDError: Excel xlsx file; not supported Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation

Examples related to django

How to fix error "ERROR: Command errored out with exit status 1: python." when trying to install django-heroku using pip Pylint "unresolved import" error in Visual Studio Code Is it better to use path() or url() in urls.py for django 2.0? Unable to import path from django.urls Error loading MySQLdb Module 'Did you install mysqlclient or MySQL-python?' ImportError: Couldn't import Django Django - Reverse for '' not found. '' is not a valid view function or pattern name Class has no objects member Getting TypeError: __init__() missing 1 required positional argument: 'on_delete' when trying to add parent table after child table with entries How to switch Python versions in Terminal?

Examples related to macos

Problems with installation of Google App Engine SDK for php in OS X dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac Could not install packages due to an EnvironmentError: [Errno 13] How do I install Java on Mac OSX allowing version switching? Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Can't compile C program on a Mac after upgrade to Mojave You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory. (mac user) How can I install a previous version of Python 3 in macOS using homebrew? Could not install packages due to a "Environment error :[error 13]: permission denied : 'usr/local/bin/f2py'"

Examples related to postgresql

Subtracting 1 day from a timestamp date pgadmin4 : postgresql application server could not be contacted. Psql could not connect to server: No such file or directory, 5432 error? How to persist data in a dockerized postgres database using volumes input file appears to be a text format dump. Please use psql Postgres: check if array field contains value? Add timestamp column with default NOW() for new rows only Can't connect to Postgresql on port 5432 How to insert current datetime in postgresql insert query Connecting to Postgresql in a docker container from outside