0
votes

I wanted to use weave to compile C code for using with python Anaconda 64 but it fails. Various problems were encountered. Code below

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) seems anaconda don't deliver msvcr90.dll with symbols. See python27.def "Symbol table not found" when trying weave

2) some mismatch occurs for 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,

there is redefinition of hypot to _hypot in pyconfig.h file. Fix for this error was in line 1121 of cmath to comment out hypot

1121 // using ::hypot;

Finally it was possible to compile the weave code but error ImportError: DLL load failed: %1 is not a valid Win32 application occurs. See logfile below it happens for both gcc compilers from MINGW64 and TDM CODEBLOCKS

Any idea what it can be a reason

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.
1

1 Answers

0
votes

After more investigation it was found that C compiler gcc should not be used together with Python Anaconda 64 bit under Win 10 but cl C compiler from MS Visual Studio 2017. After installing MS Visual Studio its necessary to start proper developer command prompt(x64 for 64bit Anaconda or x86 for 32 bit Anaconda ) and from this prompt start e.g. IDE (Spyder). In this case all paths are properly set to use cl as a C compiler e.g. for Cython or Weave.

In case of using Linux gcc is a default compiler and works without any problem after installation