cython:mingwコンパイラを使用する



Cython Use Mingw Compiler



この記事では、主にpythonとcythonでmingwコンパイラを構成して使用する方法を紹介します。

1.準備

  1. pythonとcythonをインストールします。
  2. mingwをインストールします。注意 pythonとmingwの桁数は同じである必要があります 。次に、mingwをPath環境変数に追加します。ここでは、64ビットのpythonとmingwを使用しています。以下に示すように:
    6141703-7750989a18fcc485.pngimage.png

次に、追加します distutils.cfg ファイル

Pythonインストールディレクトリ内C:Program FilesPythonLibdistutils新規作成distutils.cfgファイルの内容は次のとおりです。



[build] compiler=mingw32 [build_ext] compiler=mingw32

注:ファイルがディレクトリにすでに存在する場合は、上記の内容に変更してください。

第三に、変更 cygwinccompiler.py ファイル

Pythonインストールディレクトリに入るC:Program FilesPythonLibdistutils In、modify cygwinccompiler.py File、以下をget_msvcr()関数(解決用ValueError: Unknown MS Compiler version 1900)に追加します。



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

改訂された内容は次のとおりです。

def get_msvcr(): '''Include the appropriate MSVC runtime library if Python was built with MSVC 7.0 or later. ''' msc_pos = sys.version.find('MSC v.') if msc_pos != -1: msc_ver = sys.version[msc_pos + 6:msc_pos + 10] if msc_ver == '1300': # MSVC 7.0 return ['msvcr70'] elif msc_ver == '1310': # MSVC 7.1 return ['msvcr71'] elif msc_ver == '1400': # VS2005 / MSVC 8.0 return ['msvcr80'] elif msc_ver == '1500': # VS2008 / MSVC 9.0 return ['msvcr90'] elif msc_ver == '1600': # VS2010 / MSVC 10.0 return ['msvcr100'] elif msc_ver == '1900': # Visual Studio 2015 / Visual C++ 14.0 # 'msvcr140.dll no longer exists' return ['vcruntime140'] else: raise ValueError('Unknown MS Compiler version %s ' % msc_ver)

4、変換 python36.dllvcruntime140.dll ファイル

python36.dllファイルを変換します
C:Program FilesPythonlibs/libpython36.a: error adding symbols: File format not recognizedエラーを解決するために使用されます。

  1. copy C:Program FilesPythonpython36.dllデスクトップに移動して、次のコマンドを実行します。
gendef python36.dll dlltool -D python36.dll -d python36.def -l libpython36.a
  1. バックアップC:Program FilesPythonlibs/libpython36.a前のステップで生成されるファイルlibpython36.aコピー先C:Program FilesPythonlibsコンテンツの下。

vcruntime140.dllファイルを変換します
C:Program FilesPython / vcruntime140.dll: file not recognized: File format not recognizedエラーを解決するために使用されます。



  1. copy C:Program FilesPythonvcruntime140.dllデスクトップに移動して、次のコマンドを実行します。
gendef vcruntime140.dll dlltool -D vcruntime140.dll -d vcruntime140.def -l libvcruntime140.a

2.生成しますlibvcruntime140.aコピー先C:ProgramFilesPythonlibsディレクトリ。

このテスト環境 :WIN10(64)+ Python 3.6.4(64)+ MinGW7.2.0(x86_64-posix-seh-rev0)。

著作権表示:この記事は、CC 4.0BY-SA著作権表示に準拠した「txfly」のオリジナル記事です。元のソースリンクとこのステートメントを添付して転載してください。
元のリンク: https://www.jianshu.com/p/50105307dea5