Home > Article > Backend Development > How to Install Psycopg2 on Python Using \'Pip\' When pg_config Executable is Missing?
How Can I Use "Pip" to Install Psycopg2 on Python?
Installing psycopg2 using pip on your virtualenv may involve a few steps to ensure a successful installation.
The error message you're encountering indicates that the pg_config executable is not found. This executable is essential for building psycopg2 from source.
To resolve this issue, you can follow one of the two recommended options:
Option 1:
Install the psycopg2-binary package from PyPI, which provides pre-built binary wheels for Linux and Mac OS.
pip install psycopg2-binary
Option 2:
Install the prerequisites for building psycopg2 from source:
For Debian/Ubuntu users:
Python Version | Command | Note |
---|---|---|
Default Python 3 | sudo apt install libpq-dev python3-dev | |
Python 3.x | sudo apt install libpq-dev python3.x-dev | Substitute x with the specific Python version |
Python 2 | sudo apt install libpq-dev python-dev |
The above is the detailed content of How to Install Psycopg2 on Python Using \'Pip\' When pg_config Executable is Missing?. For more information, please follow other related articles on the PHP Chinese website!