Home  >  Article  >  Backend Development  >  How to Resolve \"pg_config executable not found\" Error When Installing psycopg2 for Python in Virtualenv?

How to Resolve \"pg_config executable not found\" Error When Installing psycopg2 for Python in Virtualenv?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-10-24 04:52:02765browse

How to Resolve

Installing psycopg2 with "pip" for Python

When using Python with virtualenv, you may encounter installation issues with psycopg2. This guide addresses the specific error message "pg_config executable not found" and provides two options for resolving the problem.

Option 1: Install psycopg2-binary

For Linux and Mac users, an easier solution is to install the psycopg2-binary package, which provides pre-built wheels:

pip install psycopg2-binary

Option 2: Install Prerequisites for Source Installation

If you prefer to install psycopg2 from source, ensure that the necessary prerequisites are installed:

Debian/Ubuntu

Python Version Command
Default Python 3 sudo apt install libpq-dev python3-dev
Python 3.x sudo apt install libpq-dev python3.x-dev
Python 2 sudo apt install libpq-dev python-dev

After installing the prerequisites, you can proceed with building psycopg2 from source. For further instructions, refer to the psycopg2 documentation.

The above is the detailed content of How to Resolve \"pg_config executable not found\" Error When Installing psycopg2 for Python in Virtualenv?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn