It seems mysql_config is missing on your system or the installer could not find it.
Be sure mysql_config is really installed.
For example on Debian/Ubuntu you must install the package:
sudo apt-get install libmysqlclient-dev
Maybe the mysql_config is not in your path, it will be the case when you compile by yourself
the mysql suite.
Update: For recent versions of debian/ubuntu (as of 2018) it is
sudo apt install default-libmysqlclient-dev
Note: Since a while back, there are binary wheels for Windows in PyPI, so this should no longer be an issue for Windows users. Below are solutions for Linux, Mac users, since lots of them find this post through web searches.
Option 1
Install the psycopg2-binary
PyPI package instead, it has Python wheels for Linux and Mac OS.
pip install psycopg2-binary
Option 2
Install the prerequsisites for building the psycopg2
package from source:
Debian/Ubuntu
Python 3
sudo apt install libpq-dev python3-dev
You might need to install python3.8-dev
or similar for e.g. Python 3.8.
Python 21
sudo apt install libpq-dev python-dev
If that's not enough, try
sudo apt install build-essential
or
sudo apt install postgresql-server-dev-all
as well before installing psycopg2 again.
CentOS 6
See Banjer's answer
1 Really? It's 2021
Best Answer
Try to add these env var before
If it does not work you can try with virtualenv:
Because is written on github: