我正在尝试运行hadoop,但在OS X上得到编译错误:
ImportError: Building module failed: ["CompileError: command 'llvm-gcc-4.2' failed with exit status 1n"
我的$PATH
中有/Developer/usr/bin
,并且在OS X Lion 10.7上运行最新版本的XCode。Cython是通过easy_install
安装的。
全输出:
>>> import pyximport; pyximport.install()
>>> import hadoopy
/Users/dolan/.pyxbld/temp.macosx-10.7-intel-2.7/pyrex/hadoopy/_main.c:236:22: error: getdelim.h: No such file or directory
/Users/dolan/.pyxbld/temp.macosx-10.7-intel-2.7/pyrex/hadoopy/_main.c:236:22: error: getdelim.h: No such file or directory
/Users/dolan/.pyxbld/temp.macosx-10.7-intel-2.7/pyrex/hadoopy/_main.c: In function ‘__pyx_f_7hadoopy_5_main_11HadoopyTask_read_offset_value_text’:
/Users/dolan/.pyxbld/temp.macosx-10.7-intel-2.7/pyrex/hadoopy/_main.c:4399: warning: implicit conversion shortens 64-bit value into a 32-bit value
lipo: can't open input file: /var/folders/8b/n0j5pn_13qn_x8p2v4f848zh0000gn/T//ccC8x2Ex.out (No such file or directory)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/hadoopy/__init__.py", line 22, in <module>
from _main import run, print_doc_quit
File "/Library/Python/2.7/site-packages/Cython-0.15.1-py2.7-macosx-10.7-intel.egg/pyximport/pyximport.py", line 335, in load_module
self.pyxbuild_dir)
File "/Library/Python/2.7/site-packages/Cython-0.15.1-py2.7-macosx-10.7-intel.egg/pyximport/pyximport.py", line 183, in load_module
so_path = build_module(name, pyxfilename, pyxbuild_dir)
File "/Library/Python/2.7/site-packages/Cython-0.15.1-py2.7-macosx-10.7-intel.egg/pyximport/pyximport.py", line 167, in build_module
reload_support=pyxargs.reload_support)
File "/Library/Python/2.7/site-packages/Cython-0.15.1-py2.7-macosx-10.7-intel.egg/pyximport/pyxbuild.py", line 85, in pyx_to_dll
dist.run_commands()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/Library/Python/2.7/site-packages/Cython-0.15.1-py2.7-macosx-10.7-intel.egg/Cython/Distutils/build_ext.py", line 135, in run
_build_ext.build_ext.run(self)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/build_ext.py", line 340, in run
self.build_extensions()
File "/Library/Python/2.7/site-packages/Cython-0.15.1-py2.7-macosx-10.7-intel.egg/Cython/Distutils/build_ext.py", line 143, in build_extensions
self.build_extension(ext)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/build_ext.py", line 499, in build_extension
depends=ext.depends)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/ccompiler.py", line 624, in compile
self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/unixccompiler.py", line 180, in _compile
raise CompileError, msg
ImportError: Building module failed: ["CompileError: command 'llvm-gcc-4.2' failed with exit status 1n"
对我来说,这是一个安装问题,我曾经使用下面提到的步骤修复了它:
-
git clone https://github.com/bwhite/hadoopy.git
cd hadoopy - python setup.py install
不使用pyximport,而是使用python setup.py build_ext --inplace
在适当的位置构建扩展模块(或者使用python setup.py develop
安装以进行就地开发,或者只是通过python setup.py install
进行常规安装)。对于包,您几乎总是希望运行安装程序,它将正确配置编译环境、构建和安装过程。
如果你正在使用Cython来加速你的代码(例如用于科学计算),
pyximport对你的个人脚本很有帮助。即使这样,您也可能需要引入其他库,并从多个源进行构建。在这种情况下,您可以使用pyxbld文件来设置源代码和include_dirs。例如,假设你有foo。然后,您可以在foo中放置构建指令。Pyxbld在同一目录下。例如:
#foo.pyxbld
def make_ext(modname, pyxfilename):
from distutils.extension import Extension
return Extension(name = modname,
sources=[pyxfilename, 'bar.c'],
include_dirs=['/myinclude'] )
def make_setup_args():
return dict(script_args=["--compiler=mingw32"])
现在使用foo就像下面这样简单:
import pyximport
pyximport.install()
import foo
假设没有编译错误,它实际上是透明的,但对于第一次导入模块的延迟。后续的导入将在主/profile目录的.pyxbld
子目录中查找构建的扩展。