Debian / Ubuntu: Fatal error: Python.h: No such file or Directory

by on October 28, 2012 · 14 comments· LAST UPDATED October 28, 2012

in , ,

I'm trying to install 3rd party python apps using pip command and getting the following error:

gcc -pthread -fno-strict-aliasing -fwrapv -Wall -Wstrict-prototypes -fPIC -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/usr/include/python2.7 -c src/MD2.c -o build/temp.linux-x86_64-2.7/src/MD2.o

src/MD2.c:31:20: fatal error: Python.h: No such file or directory

compilation terminated.

error: command 'gcc' failed with exit status 1

Tutorial details
DifficultyEasy (rss)
Root privilegesYes
Estimated completion timeN/A

Where can I find Python.h file and how do I fix this problem under Debian or Ubuntu Linux sever based system?

Python.h is nothing but a header file. It is used by gcc to build applications. You need to install a package called python-dev. This package includes header files, a static library and development tools for building Python modules, extending the Python interpreter or embedding Python in applications. To install this package, enter:
$ sudo apt-get install python-dev
# apt-get install python-dev
Sample outputs:

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  libexpat1-dev libssl-dev libssl-doc python2.7-dev zlib1g-dev
The following NEW packages will be installed:
  libexpat1-dev libssl-dev libssl-doc python-dev python2.7-dev zlib1g-dev
0 upgraded, 6 newly installed, 0 to remove and 2 not upgraded.
Need to get 32.5 MB of archives.
After this operation, 48.2 MB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 precise-updates/main libexpat1-dev amd64 2.0.1-7.2ubuntu1.1 [216 kB]
Get:2 precise/main zlib1g-dev amd64 1: [165 kB]
Get:3 precise-updates/main libssl-dev amd64 1.0.1-4ubuntu5.5 [1,525 kB]
Get:4 precise-updates/main libssl-doc all 1.0.1-4ubuntu5.5 [1,034 kB]
Get:5 precise-updates/main python2.7-dev amd64 2.7.3-0ubuntu3.1 [29.5 MB]
Get:6 precise/main python-dev amd64 2.7.3-0ubuntu2 [1,088 B]
Fetched 32.5 MB in 1s (21.4 MB/s)
Selecting previously unselected package libexpat1-dev.
(Reading database ... 55152 files and directories currently installed.)
Unpacking libexpat1-dev (from .../libexpat1-dev_2.0.1-7.2ubuntu1.1_amd64.deb) ...
Selecting previously unselected package zlib1g-dev.
Unpacking zlib1g-dev (from .../zlib1g-dev_1%3a1.2.3.4.dfsg-3ubuntu4_amd64.deb) ...
Selecting previously unselected package libssl-dev.
Unpacking libssl-dev (from .../libssl-dev_1.0.1-4ubuntu5.5_amd64.deb) ...
Selecting previously unselected package libssl-doc.
Unpacking libssl-doc (from .../libssl-doc_1.0.1-4ubuntu5.5_all.deb) ...
Selecting previously unselected package python2.7-dev.
Unpacking python2.7-dev (from .../python2.7-dev_2.7.3-0ubuntu3.1_amd64.deb) ...
Selecting previously unselected package python-dev.
Unpacking python-dev (from .../python-dev_2.7.3-0ubuntu2_amd64.deb) ...
Processing triggers for man-db ...
Setting up libexpat1-dev (2.0.1-7.2ubuntu1.1) ...
Setting up zlib1g-dev (1: ...
Setting up libssl-dev (1.0.1-4ubuntu5.5) ...
Setting up libssl-doc (1.0.1-4ubuntu5.5) ...
Setting up python2.7-dev (2.7.3-0ubuntu3.1) ...
Setting up python-dev (2.7.3-0ubuntu2) ...

Now, you can compile or build any python based modules.

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 14 comments… read them below or add one }

1 Andy January 19, 2013 at 10:59 am

Thanks for this! Also I had to

rm -rf ~/build

To get it to work again – because the previous results had been cached!


2 Onok February 15, 2013 at 9:36 pm

That saved me :) Thanks!


3 Derrick Coetzee April 1, 2013 at 12:03 pm

In my case (building pyskein) I needed the python3-dev package.


4 Danny Verbeek May 30, 2013 at 1:48 pm

Tnx for your post


5 scliart June 8, 2013 at 9:44 pm

Thank you.
Really helped me. :D


6 Kevin June 11, 2013 at 12:29 pm

For Fedora it is:

yum install python-devel


7 Bobinsky July 5, 2013 at 6:44 am



8 Bach January 31, 2014 at 1:55 am

thx Kev


9 Valerie Deane July 11, 2013 at 3:18 pm

Does not work for me. I get the error “no installation candidate”.


10 amr negm September 15, 2013 at 12:19 pm

thank you for help


11 Rohith November 13, 2013 at 5:31 pm

Thank you :) ..~


12 Musa Baloyi November 21, 2013 at 1:01 pm



13 Nooh P P March 11, 2014 at 6:59 am

I have installed python-dev but still..
fatal error: Python.h: No such file or directory
compilation terminated.



14 Kamil March 30, 2014 at 3:10 pm

Are you using Python3? If so, you have to install python3-dev package.


Leave a Comment

Tagged as: , , ,

Previous Faq:

Next Faq: