Ever get these red error messages telling you that GCC compiler could not find its path to Python.h?

MySQLdb/_mysql.c:38:10: fatal error: Python.h: No such file or directory
 #include "Python.h"
 compilation terminated.
 error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

Let's start troubleshooting and fixing it following these simple steps:

First Attempt

Try to locate Python.h file in your system first by typing:

$ locate Python.m

In case you get the output like below including the paths to available Python.h file in your system:

$ locate Python.h

If you get empty result or nothing comes up, proceed to the Second Attempt below.

As you can see, I did install 2 versions of python on my machine so I'd got 2 versions of Python.h in the output - one with the 2.7 and the other with 3.6.

Let's run the following command to make global symlinks to the corresponding Python version of your choice.

In this case I'll choose to link python3.6m:

$ sudo ln -sv /usr/include/python3.6m/* /usr/include/

After executing it, try whatever you're doing again. It should be working now.

Second Attempt

You should be having python-dev or corresponding dev package of your current Python version, for example:

  1. If you're using Python 2:
# for Ubuntu
$ sudo apt install python-dev

# for CentOS
sudo yum install python3-devel

2. If you're using Python 3:

 # for Ubuntu
 $ sudo apt install python3-dev
 # for CentOS
 sudo yum install python3-devel

Or you want to install any dev package of a particular Python version, ex. 3.6:

$ sudo apt install python3.6-dev

Hope you guys find these fixes useful. Happy coding!