$ sudo apt-get install libpq-dev python-dev
pip install psycopg2-binary
sudo dnf install python-devel postgresql-devel rpm-build
pip install psycopg2
sudo apt install libpq-dev python3-dev
sudo apt install build-essential
sudo apt install libpq-dev
-(option1) Incase you encounter an error installing psycopg2,
try installing the binaries instead:
pip install psycopg2-binary
-or (option2) downgrade the header file libpq5
sudo aptitude install libpq-dev # aptitude is recommended since it is better when it comes to resolving dependencies
accept the solution that recommends downgrading libpq5(usually the second recommended action)
pip install psycopg2
sudo apt-get install -y libpq5 # undo the downgrade
$ pip install psycopg2-binary