1

To build I use distutils:

python setup.py build_ext --inplace

Building a simple pyx-file works (setup.py):

from distutils.core import setup
from Cython.Build import cythonize

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

Building more than one file (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)

Building the above works fine and I see that both compilation and linking is completed successfully but it doesn't seem like the method say_hello_to2 is in the binary. Starting python, running the below shows that it's only the methods of test.pyxis in the module:

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

Is it possible to add more than one pyx-file to the extension build?

Saullo G. P. Castro
  • 56,802
  • 26
  • 179
  • 234
Asken
  • 7,679
  • 10
  • 45
  • 77

1 Answers1

1

You can pass multiple extensions like:

extensions = [Extension('test', ['test.pyx']),
              Extension('test2', ['test2.pyx'])]
Saullo G. P. Castro
  • 56,802
  • 26
  • 179
  • 234