jheyse
jheyse

Reputation: 489

Cythonize python modules to a different target directory

I'm trying to cythonize some python modules (on windows) and want the resulting .c files stored in a different directory.

I tried something like this:

from Cython.Build import cythonize
module_list = cythonize(r'C:\myproject\module.py', 
                        force=True,
                        build_dir=r'C:\myproject\compiled_modules')

The compilation is done but the file module.c is created in C:\myproject and not in C:\myproject\compiled_modules as expected. What am I doing wrong?

Upvotes: 2

Views: 1825

Answers (1)

Scott Maddox
Scott Maddox

Reputation: 139

I'm not sure the cythonize function can be coerced into doing that. I would just use the command line:

/path/to/cython yourmod.py -o compiled_modules/yourmod.c

Edit:

This command can be called from a python script using the subprocess module:

import subprocess
subprocess.check_call(["/path/to/cython", "yourmod.py", "-o", "compiled_modules/yourmod.c"])

Edit 2:

According to this Sage developer, relocating the c/cpp files is not supported by cython, so it looks like either compiling from the command line or using a normal configuration and then moving the c/cpp files are your only options.

Upvotes: 2

Related Questions