Skip to content Skip to sidebar Skip to footer

How To Install Psycopg2 With Pg_config Error?

I've tried to install psycopg2 (PostgreSQL Database adapater) from this site, but when I try to install after I cd into the package and write python setup.py install I get the f

Solution 1:

Debian/Ubuntu

Python 2

sudo apt install libpq-dev python-dev

Python 3

sudo apt install libpq-dev python3-dev

Additional

If none of the above solve your issue, try

sudo apt install build-essential
or

sudo apt install postgresql-server-dev-all

With pip

Install the psycopg2-binary PyPI package instead, it has Python wheels for Linux and Mac OS.

pip install psycopg2-binary

Solution 2:

I was getting this issue because I hadn't yet installed PostgreSQL on my machine yet. On mac just a simple brew install postgresql fixed the problem.

Solution 3:

If you need to install without compiling:

pip install psycopg2-binary

https://www.psycopg.org/docs/install.html#binary-install-from-pypi

Note: The psycopg2-binary package is meant for beginners to start playing with Python and PostgreSQL without the need to meet the build requirements. If you are the maintainer of a publish package depending on psycopg2 you shouldn’t use ‘psycopg2-binary’ as a module dependency. For production use you are advised to use the source distribution.

Solution 4:

If you are on Ubuntu or any other debian-based distro, try

sudo apt-get install python3-psycopg2

Otherwise, you need to find and install the Postgresql client packages for your distribution. psycopg2 installation from source

Solution 5:

Upgrading pip worked for me: pip install --upgrade pip

Post a Comment for "How To Install Psycopg2 With Pg_config Error?"