Я хотел использовать 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) происходит некоторое несоответствие для гипотеты
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 есть переопределение гипотеты для _hypot.h файл.Исправление этой ошибки было в строке 1121 cmath, чтобы закомментировать гипотезу
1121 // using ::hypot;
Наконец-то удалось скомпилировать код переплетения, но ошибка ImportError: сбой загрузки DLL:% 1 не является допустимым приложением Win32.Посмотрите файл журнала ниже, это происходит для обоих компиляторов gcc из MINGW64 и TDM CODEBLOCKS
Любая идея, что может быть причиной
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.