要构建我使用 distutils:
python setup.py build_ext --inplace
构建一个简单的pyx
文件(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
是否可以在扩展构建中添加多个-file?