Python64 + win10_64 + cython + msys2 (ming64) stepped pit remember

I have been under linux with python, has been properly properly, never thought cython module compiled under windows, until yesterday ......

The process is tortuous, the solution is simple, time is running out, long story short, first to a direct portal:

https://www.jianshu.com/p/50105307dea5

Here are steps you can, because msys2 I used, so the process is a little twists and turns, the lower side note:

msys2 be a linux system under the windows, inside it contains a total of three sets of tool chain,

Mounting the GCC example, may be directly mounted gcc this package may be mounted mingw-w64-i686-gcc or mingw-w64-x86_64-gcc

These three different packages that, gcc belongs msys2 tool chain system itself, if the compiled software, connects to the / usr / lib lower, although that is generated is exe, but is not running away msys2

And mingw-w64-i686-gcc and mingw-w64-x86_64-gcc tool is actually a cross chain, the compiler library exe only dependent on the host system, it can be directly under the windows operating system

Even mingw64 as long as it msys2 under the / bin directory system variable added to the system, it can be easily invoked.

msys2 python with the use of:

python may have three kinds of installation,

1, download the installation package from the official python installation, which is the most common practice, with msys2 completely does not matter, you can call the appropriate mingw32 or mingw64 compiler directly through the system environment variables, compile your own package

2, installed directly in msys2 Python, with msys2 of gcc, so that directly in the linux installation similar gcc python, the most convenient, is not necessary to specify a path connected to compile, experience in similar linux, the disadvantage is compiled

Exe files can not run away from msys2

3, the installation package mingw-w64-x86_64-gcc mingw-w64-x86_64-python this tool chain, this is actually similar with 1, can be compiled exe run directly in the system can also be used directly in the msys2.

Because my system has been installed python3 64bit, and a large number of packages installed, so after Bahrain msys2, installed directly mingw-w64-x86_64-gcc compiler can use this in pyhon3 in.

pacman -S mingw-w64-x86_64-gcc

Then mingw64 added to the system environment variables such as I msys2 installed in E: \ linux (yes I disguised linux Kazakhstan), the system environment variables plus a E: \ linux \ mingw64 \ bin.

According to the portal Tutorial: python installation directory in C:\Program Files\Python\Lib\distutilsthe new in distutils.cfgthe file, as follows:

[build]
compiler=mingw32

[build_ext]
compiler=mingw32

Note that this place is right, not because it is mingw64 mingw64 write, write mingw32 right.

At this time, compiling a cython program, it will be reported VC version 19,001,906 and the like, according to the curriculum such a change:

Third, modify cygwinccompiler.py file

Enter python installation directory C:\Program Files\Python\Lib\distutils, modify the cygwinccompiler.pyfile, add the following to get_msvcr()the function (to solve ValueError: Unknown MS Compiler version 1900错误).

elif msc_ver == '1900':
    # Visual Studio 2015 / Visual C++ 14.0
    # "msvcr140.dll no longer exists"
    return ['vcruntime140'] 

Because I reported it is 1906, so we changed

elif msc_ver == '1906':
    # Visual Studio 2015 / Visual C++ 14.0
    # "msvcr140.dll no longer exists"
    return ['vcruntime140']

This step must be changed according to the actual version.

Python36.dll convert files 
to solve the C: \ Program Files \ Python \ libs /libpython36.a: error Adding Symbols: File format not Recognized error. 

Copy the C: \ Program Files \ Python \ python36.dll to the desktop, execute the following command: 

gendef python36.dll 
dlltool -D python36.dll -d python36. DEF - L libpython36.a 


backup C: \ Program Files \ Python \ libs / libpython36.a file, copy the generated libpython36.a step to C: \ Program files Python \ under \ libs directory. 

Vcruntime140.dll convert files 
to solve the C: \ Program Files \ Python / vcruntime140.dll: File not Recognized: File format not Recognized error. 

Copy the C: \ Program Files \ Python \ vcruntime140.dll to the desktop, execute the following command: 
 
gendef vcruntime140.dll
dlltool. Vcruntime140.dll -D -d vcruntime140 DEF - L libvcruntime140.a

 2 . Copy the resulting libvcruntime140.a to C: \ ProgramFiles \ Python \ libs directory.

This is no problem a few steps, I was python3.7.x, so the top of the python36.dll into python37.dll, of course, I'm a python installed to the D drive, so the corresponding C: \ Program Files \ xxxxx we wanted to change D :

Further, gendef need mingw-w64-x86_64-tools-git installation

pacman -S mingw-w64-x86_64-tools-git

Otherwise, no such order.

In addition, when I compiled this cython be some compilation errors, through online search, plus -DMS_WIN64 options, solve all the problems

        self.set_executables(compiler='gcc -O -Wall -DMS_WIN64',
                             compiler_so='gcc -mdll -O -Wall -DMS_WIN64',
                             compiler_cxx='g++ -O -Wall',
                             linker_exe='gcc',
                             linker_so='%s %s %s'
                                        % (self.linker_dll, shared_option,
                                           entry_point))
        # Maybe we should also append -mthreads, but then the finished
        # dlls need another dll (mingwm10.dll see Mingw32 docs)
        # (-mthreads: Support thread-safe exception handling on `Mingw32')

        # no additional libraries needed

 

In the above

gcc -v
Using built-in specs.
COLLECT_GCC=E:\linux\mingw64\bin\gcc.exe
COLLECT_LTO_WRAPPER=E:/linux/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-9.2.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --enable-bootstrap --with-arch=x86-64 --with-tune=generic --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++ --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts=yes --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-isl-version-check --enable-lto --enable-libgomp --disable-multilib --enable-checking=release --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --enable-plugin --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev1, Built by MSYS2 project' --with-bugurl=https://sourceforge.net/projects/msys2 --with-gnu-as --with-gnu-ld
Thread model: posix
gcc version 9.2.0 (Rev1, Built by MSYS2 project)

python 3.7.3 / 3.7.4 environment by the following

 

Guess you like

Origin www.cnblogs.com/yafengabc/p/11399939.html