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

2018-12-31 08:24发布

I am trying to build a shared library using a C extension file but first I have to generate the output file using the command below:

gcc -Wall utilsmodule.c -o Utilc

After executing the command, I get this error message:

utilsmodule.c:1:20: fatal error: Python.h: No such file or directory compilation terminated.

in fact I have tried all the suggested solutions over the internet but the problem still exists ... also I have no problem with Python.h. I managed to locate the file on my machine ... anybody has faced the same problem before??

25条回答
人间绝色
2楼-- · 2018-12-31 08:47

In AWS API (centOS) its

yum install python27-devel
查看更多
皆成旧梦
3楼-- · 2018-12-31 08:48

On Ubuntu, I was running Python 3 and I had to install

sudo apt-get install python3-dev

If you want to use a version of Python that is not linked to python3, install the associated python3.x-dev package. For example:

sudo apt-get install python3.5-dev
查看更多
妖精总统
4楼-- · 2018-12-31 08:48

on Fedora run this for Python 2:

sudo dnf install python2-devel

and for Python 3:

sudo dnf install python3-devel
查看更多
伤终究还是伤i
5楼-- · 2018-12-31 08:49

It often appear when you trying to remove python3.5 and install python3.6.

So when using python3 (which python3 -V => python3.6) to install some packages required python3.5 header will appear this error.

Resolve by install python3.6-dev module.

查看更多
人间绝色
6楼-- · 2018-12-31 08:51

If you're using Python 3.6 on Amazon Linux (based on RHEL, but the RHEL answers given here didn't work):

sudo yum install python36-devel
查看更多
不再属于我。
7楼-- · 2018-12-31 08:53

For CentOS 7:

sudo yum install python36u-devel

I followed the instructions here for installing python3.6 on several VMs: https://www.digitalocean.com/community/tutorials/how-to-install-python-3-and-set-up-a-local-programming-environment-on-centos-7 and was then able to build mod_wsgi and get it working with a python3.6 virtualenv

查看更多
登录 后发表回答