How can I fix Error: pg config executable not found

When trying to install psycopg2 we get some errors. You would get to see the error, i.e., pg_config executable not found code too when you try to pip install psycopg2.

If you are seeing this error on your screen, don’t worry, we are here to solve this problem for you. Just please keep following till the end. We are going to look at the different methods to solve this issue for different OSs.

1031-error

Add this pg_config to the path dictionary or you can even specify the fully executable path which has the option of python setup.py build_ext–pg-config /path.

With the pg_config option under ‘setup.cfg’ ,go to the command prompt python setup.py egg_info failed with error code 1 in /tmp/pip-build/psycopg2.

Solution 1:

To start with the solution, you would need to install libpq-dev and python-dev (python-dev is optional). Then you would need to run pip install psycopg2. You just have to run this command to install the packages.

Command: sudo apt-get install libpq-dev python-dev

If your screen shows Python.h : No such file or directory then all you have to do is just install Python 3-dev.

Solution 2:

For this problem in Mac OS, you can move toward this solution. You would need to just run the command with the Hebrew package manager. Here is the command:

brew install postgresql

Solution 3:

And for the same issue in CentOS, install:

sudo yum install postgresql postgresql-devel python-devel

Solution 4:

For Ubuntu, you can use the equivalent command for apt-get packages. 

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

Ensure that you add in the path variable that is correct by running the following command:

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

The issue should be resolved by performing the above-mentioned steps for specific OSs.

We hope these will be helpful solutions for you to get rid of Error pg_config executable not found. 

Also, make sure that you have setuptools and wheel packages installed as well. It is specifically required if you have just created a python environment or even when the packages are required. They can never be installed as a part of a chain that belongs to other packages which are pip install setuptools wheel psycopg2. They need to be installed with the separate pip install command.