If you prefer to avoid building psycopg2 from source, please install the PyPI 'psycopg2-binary' package instead. code example
Example 1: psycopg2-binary install
pip install psycopg2-binary
Example 2: packages required to install psycopg2
pip install psycopg2-binary
Example 3: psycopg2 error install
sudo apt install libpq-dev python3-dev
sudo apt install build-essential