我想使用 weave 编译 C 代码以与 python Anaconda 64 一起使用,但它失败了。遇到了各种问题。下面的代码
import numpy
import weave
from weave import converters
def my_sum(a):
n=int(len(a))
code="""
int i;
long int counter;
counter =0;
for(i=0;i<n;i++)
{
counter=counter+a(i);
}
return_val=counter;
"""
err=weave.inline(code,['a','n'],type_converters=converters.blitz,compiler='gcc')
a = numpy.array(range(60000))
my_sum(a)
1) 似乎 anaconda 不提供带有符号的 msvcr90.dll。尝试编织时,请参阅 python27.def“找不到符号表”
2)hypot出现一些不匹配
In file included from C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/math.h:36,
from C:\ProgramData\Anaconda3\envs\Python27\include/pyport.h:325,
from C:\ProgramData\Anaconda3\envs\Python27\include/Python.h:61,
from C:\ProgramData\Anaconda3\envs\Python27\lib\site-packages\weave\scxx\object.h:11,
from C:\ProgramData\Anaconda3\envs\Python27\lib\site-packages\weave\scxx\weave_imp.cpp:7:
C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/cmath:1121:11: error: '::hypot' has not been declared
using ::hypot;
^~~~~In file included from C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/math.h:36,
from C:\ProgramData\Anaconda3\envs\Python27\include/pyport.h:325,
from C:\ProgramData\Anaconda3\envs\Python27\include/Python.h:61,
在 pyconfig.h 文件中将 hypot 重新定义为 _hypot。此错误的修复是在 cmath 的第 1121 行注释掉 hypot
1121 // using ::hypot;
最后可以编译编织代码,但出现错误 ImportError: DLL load failed: %1 is not an valid Win32 application。请参阅下面的日志文件,它适用于来自 MINGW64 和 TDM CODEBLOCKS 的 gcc 编译器
知道这可能是什么原因
running build_ext
running build_src
build_src
building extension "sc_98b95ee93f2252921d5f3dc059bd1293105" sources
build_src: building npy-pkg config files
Skip building import library: "C:\ProgramData\Anaconda3\envs\Python27\libs\libpython27.a" exists
new_compiler returns numpy.distutils.mingw32ccompiler.Mingw32CCompiler
customize Mingw32CCompiler
customize Mingw32CCompiler using build_ext
********************************************************************************
numpy.distutils.mingw32ccompiler.Mingw32CCompiler
linker_exe = ['gcc', '-g']
compiler_so = ['gcc', '-g', '-DDEBUG', '-DMS_WIN64', '-O0', '-Wall', '-Wstrict-prototypes']
archiver = ['ar', '-cr']
preprocessor = None
linker_so = ['gcc', '-g', '-shared']
compiler_cxx = ['g++']
ranlib = None
compiler = ['gcc', '-g', '-DDEBUG', '-DMS_WIN64', '-O0', '-Wall']
libraries = []
library_dirs = ['C:\\ProgramData\\Anaconda3\\envs\\Python27\\libs', 'C:\\ProgramData\\Anaconda3\\envs\\Python27\\PCbuild\\amd64', 'C:\\ProgramData\\Anaconda3\\envs\\Python27\\PC\\VS9.0\\amd64']
include_dirs = ['C:\\ProgramData\\Anaconda3\\envs\\Python27\\include', 'C:\\ProgramData\\Anaconda3\\envs\\Python27\\PC']
********************************************************************************
Skip building import library: "C:\ProgramData\Anaconda3\envs\Python27\libs\libpython27.a" exists
new_compiler returns numpy.distutils.mingw32ccompiler.Mingw32CCompiler
customize Mingw32CCompiler
customize Mingw32CCompiler using build_ext
********************************************************************************
numpy.distutils.mingw32ccompiler.Mingw32CCompiler
linker_exe = ['gcc', '-g']
compiler_so = ['gcc', '-g', '-DDEBUG', '-DMS_WIN64', '-O0', '-Wall']
archiver = ['ar', '-cr']
preprocessor = None
linker_so = ['gcc', '-g', '-shared']
compiler_cxx = ['g++']
ranlib = None
compiler = ['gcc', '-g', '-DDEBUG', '-DMS_WIN64', '-O0', '-Wall']
libraries = []
library_dirs = ['C:\\ProgramData\\Anaconda3\\envs\\Python27\\libs', 'C:\\ProgramData\\Anaconda3\\envs\\Python27\\PCbuild\\amd64', 'C:\\ProgramData\\Anaconda3\\envs\\Python27\\PC\\VS9.0\\amd64']
include_dirs = ['C:\\ProgramData\\Anaconda3\\envs\\Python27\\include', 'C:\\ProgramData\\Anaconda3\\envs\\Python27\\PC']
********************************************************************************
building 'sc_98b95ee93f2252921d5f3dc059bd1293105' extension
compiling C++ sources
C compiler: g++ -g -DDEBUG -DMS_WIN64 -O0 -Wall
compile options: '-D__MSVCRT_VERSION__=0x1500 -IC:\ProgramData\Anaconda3\envs\Python27\lib\site-packages\weave -IC:\ProgramData\Anaconda3\envs\Python27\lib\site-packages\weave\scxx -IC:\ProgramData\Anaconda3\envs\Python27\lib\site-packages\weave\blitz -IC:\ProgramData\Anaconda3\envs\Python27\lib\site-packages\numpy\core\include -IC:\ProgramData\Anaconda3\envs\Python27\include -IC:\ProgramData\Anaconda3\envs\Python27\PC -c'
g++ -g -DDEBUG -DMS_WIN64 -O0 -Wall -D__MSVCRT_VERSION__=0x1500 -IC:\ProgramData\Anaconda3\envs\Python27\lib\site-packages\weave -IC:\ProgramData\Anaconda3\envs\Python27\lib\site-packages\weave\scxx -IC:\ProgramData\Anaconda3\envs\Python27\lib\site-packages\weave\blitz -IC:\ProgramData\Anaconda3\envs\Python27\lib\site-packages\numpy\core\include -IC:\ProgramData\Anaconda3\envs\Python27\include -IC:\ProgramData\Anaconda3\envs\Python27\PC -c c:\users\krzysz~1.faj\appdata\local\temp\1\krzysztof.fajst\python27_compiled\sc_98b95ee93f2252921d5f3dc059bd1293105.cpp -o c:\users\krzysz~1.faj\appdata\local\temp\1\weave-krzysztof.fajst-iaqybo\python27_intermediate\compiler_44169fb3373e7089eb20b6ac951fd048\Release\users\krzysz~1.faj\appdata\local\temp\1\krzysztof.fajst\python27_compiled\sc_98b95ee93f2252921d5f3dc059bd1293105.og++ -g -DDEBUG -DMS_WIN64 -O0 -Wall -D__MSVCRT_VERSION__=0x1500 -IC:\ProgramData\Anaconda3\envs\Python27\lib\site-packages\weave -IC:\ProgramData\Anaconda3\envs\Python27\lib\site-packages\weave\scxx -IC:\ProgramData\Anaconda3\envs\Python27\lib\site-packages\weave\blitz -IC:\ProgramData\Anaconda3\envs\Python27\lib\site-packages\numpy\core\include -IC:\ProgramData\Anaconda3\envs\Python27\include -IC:\ProgramData\Anaconda3\envs\Python27\PC -c C:\ProgramData\Anaconda3\envs\Python27\lib\site-packages\weave\scxx\weave_imp.cpp -o c:\users\krzysz~1.faj\appdata\local\temp\1\weave-krzysztof.fajst-iaqybo\python27_intermediate\compiler_44169fb3373e7089eb20b6ac951fd048\Release\programdata\anaconda3\envs\python27\lib\site-packages\weave\scxx\weave_imp.o
exec_command(['g++', '-g', '-DDEBUG', '-DMS_WIN64', '-O0', '-Wall', '-D__MSVCRT_VERSION__=0x1500', '-IC:\\ProgramData\\Anaconda3\\envs\\Python27\\lib\\site-packages\\weave', '-IC:\\ProgramData\\Anaconda3\\envs\\Python27\\lib\\site-packages\\weave\\scxx', '-IC:\\ProgramData\\Anaconda3\\envs\\Python27\\lib\\site-packages\\weave\\blitz', '-IC:\\ProgramData\\Anaconda3\\envs\\Python27\\lib\\site-packages\\numpy\\core\\include', '-IC:\\ProgramData\\Anaconda3\\envs\\Python27\\include', '-IC:\\ProgramData\\Anaconda3\\envs\\Python27\\PC', '-c', 'C:\\ProgramData\\Anaconda3\\envs\\Python27\\lib\\site-packages\\weave\\scxx\\weave_imp.cpp', '-o', 'c:\\users\\krzysz~1.faj\\appdata\\local\\temp\\1\\weave-krzysztof.fajst-iaqybo\\python27_intermediate\\compiler_44169fb3373e7089eb20b6ac951fd048\\Release\\programdata\\anaconda3\\envs\\python27\\lib\\site-packages\\weave\\scxx\\weave_imp.o'],)exec_command(['g++', '-g', '-DDEBUG', '-DMS_WIN64', '-O0', '-Wall', '-D__MSVCRT_VERSION__=0x1500', '-IC:\\ProgramData\\Anaconda3\\envs\\Python27\\lib\\site-packages\\weave', '-IC:\\ProgramData\\Anaconda3\\envs\\Python27\\lib\\site-packages\\weave\\scxx', '-IC:\\ProgramData\\Anaconda3\\envs\\Python27\\lib\\site-packages\\weave\\blitz', '-IC:\\ProgramData\\Anaconda3\\envs\\Python27\\lib\\site-packages\\numpy\\core\\include', '-IC:\\ProgramData\\Anaconda3\\envs\\Python27\\include', '-IC:\\ProgramData\\Anaconda3\\envs\\Python27\\PC', '-c', 'c:\\users\\krzysz~1.faj\\appdata\\local\\temp\\1\\krzysztof.fajst\\python27_compiled\\sc_98b95ee93f2252921d5f3dc059bd1293105.cpp', '-o', 'c:\\users\\krzysz~1.faj\\appdata\\local\\temp\\1\\weave-krzysztof.fajst-iaqybo\\python27_intermediate\\compiler_44169fb3373e7089eb20b6ac951fd048\\Release\\users\\krzysz~1.faj\\appdata\\local\\temp\\1\\krzysztof.fajst\\python27_compiled\\sc_98b95ee93f2252921d5f3dc059bd1293105.o'],)
Retaining cwd: c:\users\krzysz~1.faj\appdata\local\temp\1\krzysztof.fajst\python27_compiledRetaining cwd: c:\users\krzysz~1.faj\appdata\local\temp\1\krzysztof.fajst\python27_compiled
_preserve_environment([])_preserve_environment([])
_update_environment(...)_update_environment(...)
_update_environment(...)
_update_environment(...)
g++ -g -shared c:\users\krzysz~1.faj\appdata\local\temp\1\weave-krzysztof.fajst-iaqybo\python27_intermediate\compiler_44169fb3373e7089eb20b6ac951fd048\Release\users\krzysz~1.faj\appdata\local\temp\1\krzysztof.fajst\python27_compiled\sc_98b95ee93f2252921d5f3dc059bd1293105.o c:\users\krzysz~1.faj\appdata\local\temp\1\weave-krzysztof.fajst-iaqybo\python27_intermediate\compiler_44169fb3373e7089eb20b6ac951fd048\Release\programdata\anaconda3\envs\python27\lib\site-packages\weave\scxx\weave_imp.o -LC:\ProgramData\Anaconda3\envs\Python27\libs -LC:\ProgramData\Anaconda3\envs\Python27\PCbuild\amd64 -LC:\ProgramData\Anaconda3\envs\Python27\PC\VS9.0\amd64 -lpython27 -lmsvcr90 -o c:\users\krzysz~1.faj\appdata\local\temp\1\krzysztof.fajst\python27_compiled\sc_98b95ee93f2252921d5f3dc059bd1293105.pyd
exec_command(['g++', '-g', '-shared', 'c:\\users\\krzysz~1.faj\\appdata\\local\\temp\\1\\weave-krzysztof.fajst-iaqybo\\python27_intermediate\\compiler_44169fb3373e7089eb20b6ac951fd048\\Release\\users\\krzysz~1.faj\\appdata\\local\\temp\\1\\krzysztof.fajst\\python27_compiled\\sc_98b95ee93f2252921d5f3dc059bd1293105.o', 'c:\\users\\krzysz~1.faj\\appdata\\local\\temp\\1\\weave-krzysztof.fajst-iaqybo\\python27_intermediate\\compiler_44169fb3373e7089eb20b6ac951fd048\\Release\\programdata\\anaconda3\\envs\\python27\\lib\\site-packages\\weave\\scxx\\weave_imp.o', '-LC:\\ProgramData\\Anaconda3\\envs\\Python27\\libs', '-LC:\\ProgramData\\Anaconda3\\envs\\Python27\\PCbuild\\amd64', '-LC:\\ProgramData\\Anaconda3\\envs\\Python27\\PC\\VS9.0\\amd64', '-lpython27', '-lmsvcr90', '-o', 'c:\\users\\krzysz~1.faj\\appdata\\local\\temp\\1\\krzysztof.fajst\\python27_compiled\\sc_98b95ee93f2252921d5f3dc059bd1293105.pyd'],)
Retaining cwd: c:\users\krzysz~1.faj\appdata\local\temp\1\krzysztof.fajst\python27_compiled
_preserve_environment([])
_update_environment(...)
_update_environment(...)
Traceback (most recent call last):
File "<ipython-input-2-fc41d47f58a9>", line 20, in <module>
my_sum(a)
File "<ipython-input-2-fc41d47f58a9>", line 14, in my_sum
err=weave.inline(code,['a','n'],type_converters=converters.blitz,compiler='gcc')
File "C:\ProgramData\Anaconda3\envs\Python27\lib\site-packages\weave\inline_tools.py", line 366, in inline
**kw)
File "C:\ProgramData\Anaconda3\envs\Python27\lib\site-packages\weave\inline_tools.py", line 502, in compile_function
exec('import ' + module_name)
File "<string>", line 1, in <module>
ImportError: DLL load failed: %1 is not a valid Win32 application.