在Windows 8上为python 2.7构建带有多个pyx文件的cython

时间:2014-08-20 09:36:01

标签: python c compilation cython python-extensions

要构建我使用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)
)

test2.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 - 文件?

1 个答案:

答案 0 :(得分:1)

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

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