Pg_config is an excellent utility for developers and system administrators. In this tutorial, we will learn how to resolve the “pg_config executable not found” error.
Cause #1 – Add PostgreSQL binaries to Path
If you have PostgreSQL and the required dependencies installed on your system, you must ensure that the target binaries are available in your system’s path.
The PostgreSQL binaries should be added to the path by default, depending on the installation method.
You can verify by running the command:
The command above should return the directory where the pg_config binary is located.
If you do not see any output from the above command, you need to ensure that PostgreSQL is installed successfully. Then, add the binaries to the path.
You can do so by running the command shown below:
Feel free to replace the path to the bin directory with the location where you have PostgreSQL installed.
Cause #2 – Missing Required Packages
Another common cause of the pg_config executable not found error is missing dependencies.
On Linux, you need to install the Python development package and libpq-dev packages before using the pg_config command.
You can resolve this by trying the solutions provided below.
Solution #1
On Debian and Debian-based distributions, you can resolve this error by installing the packages as shown below:
If you are running Python 2.x, replace the python3-dev with python-dev.
On macOS, use brew to install PostgreSQL and the required dependencies as shown:
On CentOS and REHL, run the command:
On OpenSUSE, run the command:
$ sudo ipper install python-devel
Solution #2
In some cases, the above methods may not resolve this issue. For that, you need to install the Psycopg2 package. This is a Python package implemented in C that facilitates efficient and secure communication between your Python application and the PostgreSQL server. It also provides cursors, async communication, notifications, and etc.
You can install it by running the command:
You can also use setup.py using the commands:
$ sudo python setup.py install
Conclusion
In this article, you discovered various methods and techniques to resolve the pg_config executable not found error.