摆脱pyximport

时间:2017-09-26 09:19:43

标签: cython spyder

我正在尝试使用Cython。我使用setup.py和build而不是让pyximport这样做。但是,每次导入我的模块时,都会调用pyximport。 Pyximport无法构建,一切都崩溃了。

我使用Spyder。在我的项目中我没有对pyximport的单一引用,但是Spyder似乎并不关心并且一直在调用pyximprot。

我从命令窗口(Spyder外部)调用了我的程序,它运行得很好。

我如何摆脱对pyximport的调用?或者还有其他事情发生了吗?

import c_result
Traceback (most recent call last):

  File "<ipython-input-2-3e92d1c50179>", line 1, in <module>
    import c_result

  File "C:\Users\ac22376.ONEADR\AppData\Local\Continuum\Anaconda3\lib\site-packages\pyximport\pyximport.py", line 458, in load_module
language_level=self.language_level)

  File "C:\Users\ac22376.ONEADR\AppData\Local\Continuum\Anaconda3\lib\site-packages\pyximport\pyximport.py", line 231, in load_module
raise exc.with_traceback(tb)

  File "C:\Users\ac22376.ONEADR\AppData\Local\Continuum\Anaconda3\lib\site-packages\pyximport\pyximport.py", line 215, in load_module
inplace=build_inplace, language_level=language_level)

  File "C:\Users\ac22376.ONEADR\AppData\Local\Continuum\Anaconda3\lib\site-packages\pyximport\pyximport.py", line 191, in build_module
reload_support=pyxargs.reload_support)

  File "C:\Users\ac22376.ONEADR\AppData\Local\Continuum\Anaconda3\lib\site-packages\pyximport\pyxbuild.py", line 102, in pyx_to_dll
dist.run_commands()

  File "C:\Users\ac22376.ONEADR\AppData\Local\Continuum\Anaconda3\lib\distutils\dist.py", line 955, in run_commands
self.run_command(cmd)

  File "C:\Users\ac22376.ONEADR\AppData\Local\Continuum\Anaconda3\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()

  File "C:\Users\ac22376.ONEADR\AppData\Local\Continuum\Anaconda3\lib\site-packages\Cython\Distutils\old_build_ext.py", line 185, in run
_build_ext.build_ext.run(self)

  File "C:\Users\ac22376.ONEADR\AppData\Local\Continuum\Anaconda3\lib\distutils\command\build_ext.py", line 339, in run
self.build_extensions()

  File "C:\Users\ac22376.ONEADR\AppData\Local\Continuum\Anaconda3\lib\site-packages\Cython\Distutils\old_build_ext.py", line 192, in build_extensions
ext.sources = self.cython_sources(ext.sources, ext)

  File "C:\Users\ac22376.ONEADR\AppData\Local\Continuum\Anaconda3\lib\site-packages\Cython\Distutils\old_build_ext.py", line 327, in cython_sources
self.mkpath(os.path.dirname(target))

  File "C:\Users\ac22376.ONEADR\AppData\Local\Continuum\Anaconda3\lib\distutils\cmd.py", line 338, in mkpath
dir_util.mkpath(name, mode, dry_run=self.dry_run)

 File "C:\Users\ac22376.ONEADR\AppData\Local\Continuum\Anaconda3\lib\distutils\dir_util.py", line 74, in mkpath
"could not create '%s': %s" % (head, exc.args[-1]))

ImportError: Building module c_result failed: ["distutils.errors.DistutilsFileError: could not create 'C:\\Windows\\system32\\config\\systemprofile': Kan ikke opprette en fil når filen allerede finnes\n"]

2 个答案:

答案 0 :(得分:7)

问题出现在Spyder中,因为软件包的初始化实际上会在文件utils/site/sitecustomize.py中加载pyximport并调用pyximport.install()

其他人在GitHub上抱怨过:

一个不优雅的解决方案(例如,在spyder更新后无法生存)但是应该可以在你的spyder安装中手动编辑sitecustomize.py文件并删除if HAS_PYXIMPORT:下的部分

答案 1 :(得分:4)

Spyder维护者)此问题已于2018年3月发布的 3.2.8 版本中修复。