Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does cython pyximport compile?

Tags:

python

cython

My cython / pyximport code works very well on a read/write filesystem.

But (for testing purposes), I need to try it on a read only filesystem.

How to change the cython / pyximport temporary directory ? (where does it do the job? i.e. the on-the-fly compilation?)

How to set this "working directory" to somewhere else than the current directory, for example /tmp/ (which is not ro, but rw) ?


Traceback:

!!   File "/usr/lib/python2.7/site-packages/Cython/Distutils/build_ext.py", line 301, in cython_sources
    self.mkpath(os.path.dirname(target))
!!   File "/usr/lib/python2.7/distutils/cmd.py", line 352, in mkpath
    dir_util.mkpath(name, mode, dry_run=self.dry_run)
!!   File "/usr/lib/python2.7/distutils/dir_util.py", line 76, in mkpath
    "could not create '%s': %s" % (head, exc.args[-1]))
!! ImportError: Building module samplerbox_audio failed: ["DistutilsFileError: could not create '/root/.pyxbld': Read-only file system\n"]
like image 655
Basj Avatar asked May 06 '15 14:05

Basj


People also ask

What does Cython compile to?

The cythonize command takes a . py or . pyx file and compiles it into a C/C++ file. It then compiles the C/C++ file into an extension module which is directly importable from Python.

Is Cython compiled or interpreted?

Cython is a compiled language that is typically used to generate CPython extension modules.

Can Cython compile all Python code?

Cython is a static compiler for Python and Cython programming languages, it simplifies the job of writing Python C extensions. Cython allows us to compile Python code, the result is dynamic libraries that can be used as python modules too.

How much faster is Cython than Python?

Note that regular Python takes more than 500 seconds for executing the above code while Cython just takes around 1 second. Thus, Cython is 500x times faster than Python for summing 1 billion numbers.


1 Answers

From help(pyximport.install)

By default, compiled modules will end up in a .pyxbld directory in the user's home directory. Passing a different path as build_dir will override this.

so pass build_dir as an argument when you call pyximport.install to make it use your read/write system.

like image 167
DavidW Avatar answered Sep 20 '22 03:09

DavidW