1

我是新手,我不知道是什么导致了这个错误。该错误也发生在其他代码示例上,因此它不是特定代码。我正在使用 Windows 7 和 python 2.7。感谢任何能提供帮助的人!

>>> from scipy import weave
>>> a = 1
>>> weave.inline('printf("%d\\n",a);',['a'])

No module named msvccompiler in numpy.distutils; trying from distutils
Looking for python27.dll
Looking for python27.dll


Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    weave.inline('printf("%d\\n",a);',['a'])
  File "C:\Python27\lib\scipy\weave\inline_tools.py", line 366, in inline
    **kw)
  File "C:\Python27\lib\scipy\weave\inline_tools.py", line 496, in compile_function
    verbose=verbose, **kw)
  File "C:\Python27\lib\scipy\weave\ext_tools.py", line 373, in compile
    verbose=verbose, **kw)
  File "C:\Python27\lib\scipy\weave\build_tools.py", line 279, in build_extension
    setup(name=module_name, ext_modules=[ext],verbose=verb)
  File "C:\Python27\lib\site-packages\numpy\distutils\core.py", line 169, in setup
    return old_setup(**new_attr)
  File "C:\Python27\lib\distutils\core.py", line 166, in setup
    raise SystemExit, "error: " + str(msg)
CompileError: error: Command "g++ -m64 -g -shared c:\users\owner\appdata\local\temp\scipy-owner-tbcany\python27_intermediate\compiler_e3b0c44298fc1c149afbf4c8996fb924\Release\users\owner\appdata\local\temp\owner\python27_compiled\sc_cb1945ea063627b5855c13eafebb07042.o c:\users\owner\appdata\local\temp\scipy-owner-tbcany\python27_intermediate\compiler_e3b0c44298fc1c149afbf4c8996fb924\Release\python27\lib\scipy\weave\scxx\weave_imp.o -LC:\Python27\libs -LC:\Python27\PCbuild\amd64 -lpython27 -lmsvcr90 -o c:\users\owner\appdata\local\temp\owner\python27_compiled\sc_cb1945ea063627b5855c13eafebb07042.pyd" failed with exit status 1

weave.test() 没有发现任何错误,但它只运行了 146 个测试,文档http://docs.scipy.org/doc/scipy/reference/tutorial/weave.html说它应该运行 180 个。

>>> weave.test()
Running unit tests for scipy.weave
NumPy version 1.9.1
NumPy is installed in C:\Python27\lib\site-packages\numpy
SciPy version 0.15.1
SciPy is installed in C:\Python27\lib\scipy
Python version 2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)]
nose version 1.3.7
..................................S.SSS....SSSSSS.................................................................................................
----------------------------------------------------------------------
Ran 146 tests in 3.439s

OK (SKIP=10)
<nose.result.TextTestResult run=146 errors=0 failures=0>
4

1 回答 1

1

...很久以前,我遇到了编译weave代码的问题。该问题可能是由 (Visual Studio) 预编译的 Python 与 MinGW 编译的weave代码混合引起的。

那时,我正在使用 MinGW64 编译器(MinGW32 也可以)并开发了一个三步解决方法。

1)在<pythondir>\libs目录中,删除MSVCR运行时库文件,它应该被命名为libmsvcr100.alibmsvcr100d.a(或其中包含90或任何其他版本号)。同时删除文件夹中具有相同创建日期的任何文件(第一次尝试使用编织)。

2)在(可能尚未创建)文件中<pythondir>\Lib\distutils\distutils.cfg<pythondir>\Lib\site-packages\numpy\distutils\distutils.cfg我还包含了编译器定义

[build]
compiler = mingw32

也许您需要根据您的编译器类型对其进行调整。

3)在<pythondir>\Lib\site-packages\numpy\distutils\mingw32ccompiler.py第 329 行左右出现了真正的“hack”:

在函数实现中build_msvcr_libaray(debug=False)只是硬编码return False作为第一行代码。

现在重试您的weave代码...

于 2015-12-17T20:46:48.017 回答