1

ビルドには 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、モジュール内に isのメソッドのみが含まれていることがわかります。

>>> import test
>>> dir(test)
['InheritedClass', 'TestClass', '__builtins__', '__doc__', '__file__', '__name__
', '__package__', '__test__', 'fib', 'fib_no_type', 'primes', 'say_hello_to', 's
in']
>>>

拡張ビルドに複数のpyx-file を追加することは可能ですか?

4

1 に答える 1

1

次のような複数の拡張子を渡すことができます。

extensions = [Extension('test', ['test.pyx']),
              Extension('test2', ['test2.pyx'])]
于 2014-09-19T12:53:40.137 に答える