Install packages sudo apt install build-essensial libpq-dev postgresql postgresql-contrib python3-venv python3-dev Test Create virtual env mkdir /tmp/testpsycopg2 cd /tmp/testpsycopg2 python3 -m venv venv source venv/bin/activate Install psycopg2 pip install psycopg2 Troubleshooting error: invalid command 'bdist_wheel' pip install wheel fatal error: libpq-fe.h: No such file or directory sudo apt install libpq-dev fatal error: Python.h: No such file or directory sudo apt install python3-dev gcc: error: x86_64-linux-gnu-gcc: No such file or directory sudo apt install build-essential