Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile a Cython project and clean

Tags:

python

cython

I'm using:

from distutils.core import setup
from Cython.Build import cythonize
setup(ext_modules = cythonize("myfile.pyx"))

to compile myfile.pyx. Is there a way to:

  1. Have the .pyd in the current folder (instead of build/ subfolder)
  2. Clean after compile (i.e. delete build/ subfolder, delete the .c file)

without having to do it myself with os.remove(...) ?

like image 784
Basj Avatar asked May 20 '15 19:05

Basj


People also ask

How do I compile a .PYX file?

To compile the example. pyx file, select Tools | Run setup.py Task command from the main menu. In the Enter setup.py task name type build and select the build_ext task. See Create and run setup.py for more details.

What compiler does cython use?

Unlike most Python software, Cython requires a C compiler to be present on the system. The details of getting a C compiler varies according to the system used: Linux The GNU C Compiler (gcc) is usually present, or easily available through the package system.


1 Answers

You can use the --inplace option:

--inplace (-i)       ignore build-lib and put compiled extensions into the
                     source directory alongside your pure Python modules

setup.py clean should clean the build dir. setup.py clean --all cleans all build output.

like image 190
Mike Müller Avatar answered Sep 28 '22 13:09

Mike Müller