要使用distutils生成:

python setup.py build_ext --inplace

构建一个简单的pyx-file works(setup.py):
from distutils.core import setup
from Cython.Build import cythonize

setup(
    ext_modules = cythonize('test.pyx')
)

生成多个文件(setup.py):
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize

# This is the new part...
extensions = [
    Extension('test', ['test.pyx', 'test2.pyx'])
]

setup(
    ext_modules = cythonize(extensions)
)

测试2.pyx:
def say_hello_to2(name):
    print("Hello %s!" % name)

构建上面的代码工作得很好,我看到编译和链接都成功完成了,但似乎方法say_hello_to2不在二进制文件中。启动python,运行下面的代码表明模块中只有test.pyx的方法:
>>> import test
>>> dir(test)
['InheritedClass', 'TestClass', '__builtins__', '__doc__', '__file__', '__name__
', '__package__', '__test__', 'fib', 'fib_no_type', 'primes', 'say_hello_to', 's
in']
>>>

是否可以向扩展生成中添加多个pyx-文件?

最佳答案

您可以传递多个扩展名,如:

extensions = [Extension('test', ['test.pyx']),
              Extension('test2', ['test2.pyx'])]

关于python - 在Windows 8上为python 2.7用多个pyx文件构建cython,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25401364/

10-09 18:22