2

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?

asked Jul 10, 2015 at 15:51

1 Answer 1

2

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.

answered Jul 10, 2015 at 16:36
Sign up to request clarification or add additional context in comments.

3 Comments

Ok Scott. Everything is fine with using the command line, but I really want to use a python script and process many files at once. Thanks!
Updated to show how to call the command line through the subprocess module.
Great Scott! Thank you for the confirmation that it is not supported. I'll try your suggestion with the subprocess model. Answer accepted. Thanks again!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.