Cython安装找不到Python.h文件?

8
我想在我的Ubuntu 12.04系统上安装Cython,我在终端输入了以下命令。
sudo easy_install cython

作为回应,我得到了以下错误信息:
Searching for cython  
Reading http://pypi.python.org/simple/cython/  
Reading http://www.cython.org  
Reading http://cython.org  
Best match: Cython 0.16  
Downloading http://www.cython.org/release/Cython-0.16.zip  
Processing Cython-0.16.zip  
Running Cython-0.16/setup.py -q bdist_egg --dist-dir /tmp/easy_install-VzJ0lH/Cython-0.16/egg-dist-tmp-BMJs3p  
Compiling module Cython.Plex.Scanners ...  
Compiling module Cython.Plex.Actions ...  
Compiling module Cython.Compiler.Lexicon ...  
Compiling module Cython.Compiler.Scanning ...  
Compiling module Cython.Compiler.Parsing ...  
Compiling module Cython.Compiler.Visitor ...  
Compiling module Cython.Compiler.FlowControl ...  
Compiling module Cython.Compiler.Code ...  
Compiling module Cython.Runtime.refnanny ...  
warning: no files found matching '*.pyx' under directory 'Cython/Debugger/Tests'  
warning: no files found matching '*.pxd' under directory 'Cython/Debugger/Tests'  
warning: no files found matching '*.h' under directory 'Cython/Debugger/Tests'  
warning: no files found matching '*.pxd' under directory 'Cython/Utility'  
warning: no files found matching '*.h' under directory 'Cython/Utility'  
warning: no files found matching '.cpp' under directory 'Cython/Utility'  
/tmp/easy_install-VzJ0lH/Cython-0.16/Cython/Plex/Scanners.c:4:20: fatal error: Python.h: El fitxer o directori no existeix  
compilation terminated.  
error: Setup script exited with error: command 'gcc' failed with exit status 1  

抱歉这里用了加泰罗尼亚语,但“El fitxer o directori no existeix”表示该文件不存在。

我认为我可能漏掉了某些东西或不知道该怎么安装它。

还有其他人遇到同样的问题吗?或者知道如何正确安装吗?

2个回答

11

根据您安装Python的方式,您可能还需要获取开发文件(如果您使用apt-get或Synaptic安装)。

sudo apt-get install python-dev

或者也许

sudo apt-get install python2.6-dev  #substitute your python version here...
请注意,如果您需要安装任何C扩展到CPython,则这是必要的。

1
在Ubuntu 12.10(针对python2.7.5)上,我终于(!)通过指定“sudo apt-get install python2.7-dev”来解决了这个错误。我之前一直尝试使用的是python-dev。 - fooledbyprimes
@fooledbyprimes -- 很高兴你让它工作了... 顺便说一下,我甚至不记得写过这个答案 :-). 如果你今天问我如何做到这一点,我可能会被难住 ;-). - mgilson

0

我还记得在安装Cython时遇到了这个问题。 如果您进入Python安装文件夹(假设此示例为Python2.7),请将C:\ Python27 \ include目录及其所有内容复制到您的主目录或运行easy_install的目录中。 “include”目录包含“ python.h”,这是编译器的C头文件。

话虽如此,当我这样做时,它消除了该错误,但仍无法正常工作。

好运。


抱歉,但这对我不起作用,我使用的是Ubuntu,我没有那个包含文件夹。 - mid_kid

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接