Python编织编译错误

时间:2015-12-16 06:47:29

标签: python weave

我是新手编织,我不知道导致此错误的原因。错误也发生在其他代码示例上,因此它不是特定的代码。我正在使用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>

1 个答案:

答案 0 :(得分:1)

...很久以前我遇到了编译weave代码的问题。问题可能是混合(Visual Studio)预编译的Python与MinGW编译的<pythondir>\libs代码。

当时,我使用的是MinGW64编译器(MinGW32也可以使用)并开发了三步解决方法。

1)在libmsvcr100.a目录中,删除MSVCR运行时库文件,其名称应为libmsvcr100d.a90(或<pythondir>\Lib\distutils\distutils.cfg或任何其他版本数字)。随之删除文件夹中具有相同创建日期的任何文件(首次尝试使用编织)。

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

<pythondir>\Lib\site-packages\numpy\distutils\mingw32ccompiler.py

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

3)在build_msvcr_libaray(debug=False)中出现真正的&#34; hack&#34;在第329行附近:

return False的函数实现中,只需硬编码weave作为第一行代码。

现在重试您的$filename=$_FILES["image"]["name"]; $ext = explode('.', $filename); $without_extension = substr($filename, 0, strrpos($filename, ".")); $final_name=$without_extension.time().'.'.$ext 代码...