Can't find Python.h file on CentOS

2020-02-09 06:34发布

I am trying to compile a Python extension written in C on a CentOS machine. I am getting

error: Python.h: No such file or directory

It works fine on ubuntu, where I have python-dev installed using apt-get.

I tried installing python-devel using

yum install python-devel

but it is already installed. How do I fix this error?

标签: python c centos
8条回答
爱情/是我丢掉的垃圾
2楼-- · 2020-02-09 06:45

I had a similar problem where default Python was 2.7 but pip was running against 3.4, and I wanted to use 2.7. So I did: yum remove python34-pip and yum install python2-pip. Solved it!

查看更多
时光不老,我们不散
3楼-- · 2020-02-09 06:46

This depends on the Python you have!

You need a dev package, the version X.X.X for Python X.X.X you have, you can search on https://centos.pkgs.org/7/ius-x86_64.

By example, if you have Python 3.6.5 from IUS, you need to install https://centos.pkgs.org/7/ius-x86_64/python36u-devel-3.6.5-1.ius.centos7.x86_64.rpm.html.

查看更多
何必那么认真
4楼-- · 2020-02-09 06:48
  • for CentOS 7.4
    • Python 3.6.6 : yum -y install python36-devel
    • Python 2 : yum -y install python-devel
  • for Ubuntu
    • Python 3.6: apt-get install libpython3.6-dev
查看更多
Lonely孤独者°
5楼-- · 2020-02-09 06:55

Install python3.4 (include pip) & python3.4-dev packages on Centos6.X:

yum install http://dl.iuscommunity.org/pub/ius/stable/CentOS/6/x86_64/python34u-3.4.2-1.ius.centos6.x86_64.rpm
yum install http://dl.iuscommunity.org/pub/ius/stable/CentOS/6/x86_64/python34u-devel-3.4.2-1.ius.centos6.x86_64.rpm
查看更多
爷、活的狠高调
6楼-- · 2020-02-09 07:00

You should first remove original python.

sudo yum remove python

Then install python-devel by

sudo yum install python-devel

This method should be useful.

查看更多
孤傲高冷的网名
7楼-- · 2020-02-09 07:05

I too had similar problem.

./python/py_defines.h:39:20: fatal error: Python.h: No such file or directory

Whereas the find command showed that the python.h exists.

The above solutions did not work however the below command execution worked for me.

yum install python27-python-devel.x86_64

Not much different but wasted lots of time.

查看更多
登录 后发表回答