fatal error: Python.h: No such file or directory compilation terminated.

When installing pot module, an error was found as follows:

sudo pip3 install pot
The directory '/home/wdong/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/wdong/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pot
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7f68b137e320>: Failed to establish a new connection: [Errno 101] Network is unreachable',)': /packages/28/4b/7aaa1f840a359f5953dd378e0237fa8faf9b0a415ff7282b7375fbe68d27/POT-0.5.1.tar.gz
  Downloading https://files.pythonhosted.org/packages/28/4b/7aaa1f840a359f5953dd378e0237fa8faf9b0a415ff7282b7375fbe68d27/POT-0.5.1.tar.gz (720kB)
    100% |████████████████████████████████| 727kB 90kB/s 
Requirement already satisfied: numpy in /usr/local/lib/python3.5/dist-packages (from pot) (1.16.2)
Requirement already satisfied: scipy in /usr/local/lib/python3.5/dist-packages (from pot) (1.2.1)
Requirement already satisfied: cython in /usr/local/lib/python3.5/dist-packages (from pot) (0.29.6)
Requirement already satisfied: matplotlib in /usr/local/lib/python3.5/dist-packages (from pot) (3.0.3)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.5/dist-packages (from matplotlib->pot) (0.10.0)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.5/dist-packages (from matplotlib->pot) (1.0.1)
Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.5/dist-packages (from matplotlib->pot) (2.8.0)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/lib/python3/dist-packages (from matplotlib->pot) (2.0.3)
Requirement already satisfied: six in /usr/lib/python3/dist-packages (from cycler>=0.10->matplotlib->pot) (1.10.0)
Requirement already satisfied: setuptools in /usr/local/lib/python3.5/dist-packages (from kiwisolver>=1.0.1->matplotlib->pot) (40.8.0)
Installing collected packages: pot
  Running setup.py install for pot ... error
    Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-hp2npzwa/pot/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-ebdwbzel/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.5
    creating build/lib.linux-x86_64-3.5/ot
    copying ot/dr.py -> build/lib.linux-x86_64-3.5/ot
    copying ot/__init__.py -> build/lib.linux-x86_64-3.5/ot
    copying ot/gromov.py -> build/lib.linux-x86_64-3.5/ot
    copying ot/da.py -> build/lib.linux-x86_64-3.5/ot
    copying ot/plot.py -> build/lib.linux-x86_64-3.5/ot
    copying ot/utils.py -> build/lib.linux-x86_64-3.5/ot
    copying ot/datasets.py -> build/lib.linux-x86_64-3.5/ot
    copying ot/stochastic.py -> build/lib.linux-x86_64-3.5/ot
    copying ot/bregman.py -> build/lib.linux-x86_64-3.5/ot
    copying ot/optim.py -> build/lib.linux-x86_64-3.5/ot
    copying ot/smooth.py -> build/lib.linux-x86_64-3.5/ot
    creating build/lib.linux-x86_64-3.5/ot/gpu
    copying ot/gpu/__init__.py -> build/lib.linux-x86_64-3.5/ot/gpu
    copying ot/gpu/da.py -> build/lib.linux-x86_64-3.5/ot/gpu
    copying ot/gpu/utils.py -> build/lib.linux-x86_64-3.5/ot/gpu
    copying ot/gpu/bregman.py -> build/lib.linux-x86_64-3.5/ot/gpu
    creating build/lib.linux-x86_64-3.5/ot/lp
    copying ot/lp/__init__.py -> build/lib.linux-x86_64-3.5/ot/lp
    copying ot/lp/cvx.py -> build/lib.linux-x86_64-3.5/ot/lp
    creating build/lib.linux-x86_64-3.5/ot/externals
    copying ot/externals/__init__.py -> build/lib.linux-x86_64-3.5/ot/externals
    copying ot/externals/funcsigs.py -> build/lib.linux-x86_64-3.5/ot/externals
    running build_ext
    building 'ot.lp.emd_wrap' extension
    creating build/temp.linux-x86_64-3.5
    creating build/temp.linux-x86_64-3.5/ot
    creating build/temp.linux-x86_64-3.5/ot/lp
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Iot/lp -I/usr/local/lib/python3.5/dist-packages/numpy/core/include -I/tmp/pip-install-hp2npzwa/pot/ot/lp -I/usr/include/python3.5m -c ot/lp/emd_wrap.cpp -o build/temp.linux-x86_64-3.5/ot/lp/emd_wrap.o
    cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
    ot/lp/emd_wrap.cpp:28:20: fatal error: Python.h: No such file or directory
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
    
    ----------------------------------------
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-hp2npzwa/pot/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-ebdwbzel/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-hp2npzwa/pot/

Solutions:

sudo apt-get install python-dev   # for python2.x installs
sudo apt-get install python3-dev  # for python3.x installs

 

Read More: