Ubuntu 12.04中缺少Python.h


69

我使用以下命令在Ubuntu 12.04上安装了一个名为RYU的openflow控制器:

 sudo  pip install ryu

我试图使用ryu-manager运行python文件,如下所示。

sudo ryu-manager simple_switch.py 
Traceback (most recent call last):
  File "/usr/local/bin/ryu-manager", line 19, in <module>
    import gevent
ImportError: No module named gevent

然后,我尝试使用以下命令安装gevent:

sudo pip install gevent
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c gevent/core.c -o build/temp.linux-x86_64-2.7/gevent/core.o
gevent/core.c:4:20: fatal error: Python.h: No such file or directory

compilation terminated.

error: command 'gcc' failed with exit status 1

此错误的原因是什么?我试图找到Python.h使用sudo locate Python.h,但没有成功。python -V但是的输出是

Python 2.7.3

Python.h系统上应该有吗?如果是这样,我应该安装什么来获得它?


9
头文件的位置与编程有关,请投票重新打开。
vitaut

1
尝试在NGINX下运行我的Django代码时遇到此问题。那绝对与编程有关。
Craig S. Anderson

Answers:


186

应该这样做:

sudo apt-get update; sudo apt-get install python-dev -y

它将安装所有缺少的标题。这对我帮助很大。


23
如果您使用的是其他版本的Python,例如3.3:sudo apt-get install python3.3-dev
FreshPow 2014年

在Ubuntu 14.04上,命令“ sudo apt-get install python3”安装了正确的版本,而无需在命令行中指定版本。
Craig S. Anderson

在Centos7.3上遇到相同的问题。有什么建议?
维卡斯·戈尔

36

即使已安装Python,默认情况下通常也不会安装头文件和库。在Ubuntu上,它们位于一个名为的单独软件包中python-dev



0

嘿,我通过这个命令解决了这个问题

pip3安装-U git + https://github.com/kti/python-netfilterqueue

希望它能工作:)

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.