[Fixed]-How to solve ERROR: Failed building wheel for psycopg2?

45👍

Instead pip command use:

sudo apt-get install libpq-dev

then use:

pip install psycopg2

8👍

On Ubuntu, do you can install psycopg2-binary

pip install psycopg2-binary

3👍

Looks like you need to install libpq-dev according to this Problems compiling and installing psycopg2.
pip install libpq-dev should work or perhaps a specific version may be required. About psycopg2 being commented yet it being attempted to install by pip it may be a requirement of one of your other dependencies.

0👍

https://github.com/psycopg/psycopg2/issues/1331#issuecomment-890041965

This is what worked for me.
Using WSL 2 using Ubuntu-20.04.

-1👍

After installing the right psycopg2==2.8.5 version, also check if your database is spatial and the right setting is there in your settings.py file for example if you are using postgres, set your database engine connection to;

‘ENGINE’: ‘django.db.backends.postgresql_psycopg2’,

Leave a comment