我做了一个名为.py
的"hello.py"
文件,它有以下导入:
from setuptools import setup,Extension
from Cython.Build import cythonize
setup( name = 'increment app',ext_modules = cythonize("hello.pyx"))
在运行这个时,我得到一个:
AttributeError:'module'对象没有属性'locals'。
我正在使用Visual Studio C++ 2008
版本。
命令提示符pip install cython
没有给我任何错误,但它也没有下载或安装cython。
@DavidW这是完整的追溯---
AttributeErrorTraceback (most recent call last)
C:\SPB_Data\setup.py in <module>()
1 from setuptools import setup,Extension
----> 2 from Cython.Build import cythonize
3 setup( name = 'increment app',ext_modules = cythonize("hello.pyx"))
C:\Users\kalachand\AppData\Local\Enthought\Canopy32\edm\envs\User\lib\site-packages\Cython\Build\__init__.py in <module>()
----> 1 from .Dependencies import cythonize
2 from .Distutils import build_ext
C:\Users\kalachand\AppData\Local\Enthought\Canopy32\edm\envs\User\lib\site-packages\Cython\Build\Dependencies.py in <module>()
176
177
--> 178 @cython.locals(start=cython.Py_ssize_t, end=cython.Py_ssize_t)
179 def line_iter(source):
180 if isinstance(source, basestring):
AttributeError: 'module' object has no attribute 'locals'
guideline you seem to be following指示您将此代码放在setup.py
中并以相当具体的方式调用它。
python setup.py build_ext --inplace
该指南使用distutils
,而不是setuptools
。
该指南解释了如何Cython化你的其他一些代码,所以参数"hello.pyx"
也看起来不对(或用其他代码替换hello.py
,如指南中的简单print("Hello World")
示例,并将你的问题中的代码移动到setup.py
,就像我上面建议的那样)。
如果您有理由偏离文档,您应该解释偏差的基本原理,并提及这些偏离指令是否会导致您的失败。在没有测试的情况下进行多次无偿(或不进行)更改会浪费您的时间和我们的时间;另请参阅将问题作为MCVE的指南。