LoginSignup
18
15

More than 5 years have passed since last update.

Windows(x64)でPython3.6.0(x64)にPyCryptoを入れるメモ

Last updated at Posted at 2017-01-11

環境

  • Windows 8.1(x64)
  • Python 3.6.0(x64)
  • Visual Studio 2015 Community

4ヶ所でこけた

インストールは出来ましたが、以下4点でこけました。それぞれ対処方法へのポインタを張っておくので、ご参考までに。

pipでinstall pycryptoやってみたらVCのC++ Common Toolsが入ってなかった

入れましょう:http://stackoverflow.com/questions/33323172/vcvarsall-bat-needed-for-python-to-compile-missing-from-visual-studio-2015-v-1

cl.exeなどはぼんやりしてると入らないんですね。知らなかった。これを入れると、pip(がkickするsetup.py)は勝手にvcvarsall.batを叩いてcl.exeを起動する世界を作ってコンパイルしてくれる。

なおエラーメッセージではVisual C++ Build Tools入れてくれって出てきますが、これは既にVS2015が入ってるとインストールできません。

PyCryptoとコンパイラのstdint.hがバッティング

pip install pycryptoしてると途中でコンパイルエラーが起きる。

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Isrc/ -Isrc/inc-msvc/ -Id:\python36\include -Id:\python36\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Prograinclude\\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\\winrt" /Tcsrc/winrand.c /Fobuild\temp.win-amd64-3.6\Release\src/winrand.obj
winrand.c

C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(26): error C2061: syntax error: identifier 'intmax_t'
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(27): error C2061: syntax error: identifier 'rem'
(中略)
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(95): error C2143: syntax error: missing '{' before '__cdecl'
error: command 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe' failed with exit status 2

調べてみると、PyCryptoの配布パッケージに含まれるstdint.hがコンパイラのstdint.hより先にインクルード1されてintmax_tなどが定義されないままinttypes.hが読まれてた。

pipでのインストールを諦め、githubからリポジトリをcloneしてpython setup.py buildを叩くことにする。

こんなやり方もある。
次のコマンドを管理者権限のコマンドプロンプトで叩く。
vsvars32.batがあるフォルダ(C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Toolsとか)に移動して
> vsvars32.bat
> set CL=-FI"%VCINSTALLDIR%\INCLUDE\stdint.h"
> pip install pycrypto

DESモジュールのビルドがこける

src/libtom/tomcrypt_cipher.h(546): error C2133: 'cipher_descriptor': unknown size

これはgithubのissueになってます:https://github.com/dlitz/pycrypto/issues/167
書いてある通り、LTC_NO_PROTOTYPES定義してcipher_descriptor[]を消すとビルドが通ります。

testが帰ってこない

ERROR: runTest (Crypto.SelfTest.Random.test__UserFriendlyRNG.RNGMultiprocessingForkTest)

python setup.py testでテストを試みると、途中でエラー吐いて終了しません。
これも、前述のgithubのissueになっています。

修正内容はプルリク見たほうが早い:https://github.com/dlitz/pycrypto/pull/200

> python setup.py test
running test
running build
running build_py
running build_ext
warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.
SelfTest: warning: not testing _fastmath module (not available)
SelfTest: warning: not testing _fastmath module (not available)
SelfTest: warning: not testing _fastmath module (not available)
.............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................SelfTest: You can ignore the RandomPool_DeprecationWarning that follows.
....................................................
----------------------------------------------------------------------
Ran 1297 tests in 77.406s

OK

やったぜ。


  1. コンパイル失敗したコマンドラインを見れば分かる通り、C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDEより先にsrc/inc-msvc/が参照される。 

18
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
15