Michael WS Michael WS -4 years ago 126
Python Question

Specify cython output file

It seems that by default setup from distutils.core with cmdclass set to build_ext, compiles a cpp or c file in the current working directory. Is there a way to determine where the generated c code is written to? Otherwise a repository will be littered with generated code.

For example this file setup.py will write a file example.c to the current working directory:

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

ext_modules = cythonize("example.pyx"))

Answer Source

You can pass the option build_dir="directory name" to Cythonize

# rest of file as before
      ext_modules = cythonize("example.pyx",

The above code will put the generated c files in the directory "build" (which makes sense, since by default it's where distutils puts temporary object files and so forth when it's building).

My original answer had working, not build_dir. Thanks to @ArthurTacca for pointing out that that no longer seems to be right.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download