When installing psycopg2 on your Linx, Mac, or Windows machine, you may encounter an error something like this:
As you can see in the error message, you need to add a directory that has pg_config to the PATH. For this, you need to install a few dependencies like libpq-dev and python-dev (optional).
Here are the steps you need to follow:
If you see a message that says Python.h: No such file or directory, you need to install python3-dev and check if the error is fixed.
So that’s how you fix the pg_config executable not found error. For more assistance, get in touch with the support team.
Code:
Error: pg_config executable not found.
Please add the directory containing pg_config to the PATH
Here are the steps you need to follow:
- Run this command which would install the packages:
Code:
sudo apt-get install libpq-dev python-dev
- If you’re on macOS, you need to run the following command:
Code:
brew install postgresql
- If you’re on CentOS, you have to execute this command:
Code:
sudo yum install postgresql postgresql-devel python-devel
- Ubuntu users have to use this command:
Code:
sudo apt-get install postgresql postgresql-dev python-dev
- Lastly, you have to add in the path variable. Then include the correct path. Here’s the command to execute:
Code:
sudo PATH=$PATH:/usr/pgsql-9.3/bin/ pip install psycopg2