Cython的pyximport编译文件存放在哪里?

9

我的cython / pyximport代码在读写文件系统上运行得非常好。

但是(为了测试目的),我需要在一个只读文件系统上尝试它。

如何更改cython / pyximport临时目录?(它在哪里执行任务?即动态编译?)

如何将此“工作目录”设置为当前目录以外的其他位置,例如/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"]
2个回答

16

来自help(pyximport.install)

默认情况下,编译的模块将会保存在用户主目录下的.pyxbld 目录中。如果传递一个不同的路径作为 build_dir 参数,则会覆盖此设置。

因此,在调用pyximport.install时,传递build_dir参数,以便使其使用您的读/写系统。


1

从Cython文档链接

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

docs

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接