cython pyximport 在哪里编译?

Where does cython pyximport compile?

我的 cython / pyximport 代码在 read/write 文件系统上运行良好。

但是(出于测试目的),我需要在 只读文件系统.

上尝试

如何更改cython/pyximport临时目录? (它在哪里完成工作?即即时编译?)

如何将此 "working directory" 设置到当前目录以外的其他位置,例如 /tmp/(不是 ro,而是 rw)?


回溯:

!!   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"]

来自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.

因此,当您调用 pyximport.install 时将 build_dir 作为参数传递,以使其使用您的 read/write 系统。

来自 Cython 文档 Link

传递 build_dir 参数,其值等于要编译模块的路径,这将覆盖主目录

例如

pyximport.install(build_dir="/mnt/f/")