3

I was looking for a method to compile multiple pyx-files using only setup.py file. The solution was found in the official documentation:

ext_modules = [Extension("*", ["*.pyx"])]
setup(ext_modules=cythonize(ext_modules))

This will compile all pyx-files within the current directory and create a shared-object for each single file. However, someone suggested this alternative:

ext_modules = [Extension("*", [file for file in os.listdir("folder_where_your_pyx_files_are") 
                                             if file.endswith('.pyx'])]
setup(ext_modules=cythonize(ext_modules))

Which will compile all pyx-files into one shared-object. However none of the imports are working properly.(e.g. if there imports between the files, none of them will work)

So my question is: Is there a use case for compiling multiple pyx-file into one extension module ?

Note: I am new to cython and have little knowledge about Extension module.

Felix Hohnstein
  • 459
  • 5
  • 13
  • Does this answer your question? [Collapse multiple submodules to one Cython extension](https://stackoverflow.com/questions/30157363/collapse-multiple-submodules-to-one-cython-extension) – ead Dec 11 '20 at 08:34
  • @ead I'm not completely convinced that this is a duplicate. This question is asking "why would I want to compile multiple modules together?" while the one you linked is about "how to compile multiple modules together?" – DavidW Dec 11 '20 at 09:22
  • @FelixHohnstein I would stay away from this unless you want to get very familiar with the fine details of the Python import mechanism. If you don't already have a good reason to do so then don't try to find one. – DavidW Dec 11 '20 at 09:23
  • @DavidW you are probably right, "related" would be better here than dupe. – ead Dec 11 '20 at 09:41
  • @ead Thank you. This is a good start. Maybe you should post this as answer .. so others might read it as well. – Felix Hohnstein Dec 11 '20 at 11:58
  • @DavidW I will listen to your suggestion and leave it be. Tho learning more is always a plus for me. – Felix Hohnstein Dec 11 '20 at 12:00

0 Answers0