Numpy Cimport错误使用cython

时间:2011-11-03 14:45:32

标签: python numpy cython

我正在尝试从.pyx文件中将Numpy嵌入到Python 2.7 shell中,但它一直给我同样的错误:

我创建了一个名为.pyx的{​​{1}}文件,只是为了查看它是否是我正在运行的更大代码的一部分,该文件包含:

numpyx

我每次都会收到以下错误:

cimport numpy as np
a = np.arange(0,10)
print 'a= ',a

我不明白为什么它不起作用,因为只要Traceback (most recent call last): File "<pyshell#82>", line 1, in <module> import numpyx File "C:\Users\Scott\AppData\Roaming\Python\Python27\site-packages\pyximport \pyximport.py", line 335, in load_module self.pyxbuild_dir) File "C:\Users\Scott\AppData\Roaming\Python\Python27\site-packages\pyximport\pyximport.py", line 183, in load_module so_path = build_module(name, pyxfilename, pyxbuild_dir) File "C:\Users\Scott\AppData\Roaming\Python\Python27\site-packages\pyximport\pyximport.py", line 167, in build_module reload_support=pyxargs.reload_support) File "C:\Users\Scott\AppData\Roaming\Python\Python27\site-packages\pyximport\pyxbuild.py", line 85, in pyx_to_dll dist.run_commands() File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands self.run_command(cmd) File "C:\Python27\lib\distutils\dist.py", line 972, in run_command cmd_obj.run() File "C:\Users\Scott\AppData\Roaming\Python\Python27\site-packages\Cython\Distutils\build_ext.py", line 135, in run _ build_ext.build_ext.run(self) File "C:\Python27\lib\distutils\command\build_ext.py", line 340, in run self.build_extensions() File "C:\Users\Scott\AppData\Roaming\Python\Python27\site-packages\Cython\Distutils\build_ext.py", line 143, in build_extensions self.build_extension(ext) File "C:\Python27\lib\distutils\command\build_ext.py", line 499, in build_extension depends=ext.depends) File "C:\Python27\lib\distutils\ccompiler.py", line 624, in compile self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) File "C:\Python27\lib\distutils\cygwinccompiler.py", line 166, in _compile raise CompileError, msg ImportError: Building module failed: ["CompileError: command 'gcc' failed with exit status 1\n"] 不在其中就可以编译.pyx个文件。

如果有人能够对此有所了解,那就太棒了!

1 个答案:

答案 0 :(得分:0)

你想要的功能在python包中可用。 (我在numpy.pxd中找不到linspace的引用)

我通常会沿着这些方向做点什么:

import numpy as np
cimport numpy as cnp

def foo(double x):
    cdef cnp.ndarray[cnp.float64_t, ndim=1] y = np.linspace(0, 10, 11)
    # do whatever
    return y