Pythonの拡張モジュールであるPyCryptoをビルドしてWindowsへインストールしようとしたところ、以下のエラーが出たため対処した時のメモを残します。
(env) >pip install pycrypto ... building 'Crypto.Random.OSRNG.winrandom' extension error: Unable to find vcvarsall.bat
環境
- Windows10 x64
- Python 3.5.1 32bit
- PyCrypto 2.6.1
- Visual Studio なし
調査
このエラーの場合、Visual Studio Community 2015でVisual C++ 2015用の共通ツール
をインストールすれば、ビルド・インストールできます。
vcvarsall.bat needed for python to compile missing from visual studio 2015 ( v 14) - Stack Overflow
今回はVisual Studioを入れたくない環境だったため、Visual Studio無しの方法を調べたところ、以下の記事がありました。
Windows での Python 2.7, 3.4, 3.5 の拡張モジュールビルド環境 - Qiita
記事の中で、
また、 Visual C++ Build tools のベータ版が発表されました。
未検証ですが、これを使えば Python 2.7 と同じように重量級の Visual Studio をインストールしなくても必要なコンパイラーなどのツール一式が手に入ると思います。
とあったため、リンク先を見てみました。
Announcing Visual C++ Build Tools 2015 – standalone C++ tools for build environments | Visual C++ Team Blog
しかし、現在ではDownload Visual C++ Build Tools 2015 (pre-release)
のリンクからはダウンロードできませんでした。
そのため、もしかしたら最新の記事があるかもしれないと調べてみたところ、Visual C++ Build Tools 2015の正式版リリースの記事がありました。
Announcing the official release of the Visual C++ Build Tools 2015 | Visual C++ Team Blog
ページ中央のDownload the Visual C++ Build Tools 2015 now!
のリンクより、Visual C++ Build Tools 2015のインストーラーvisualcppbuildtools_full.exe
が手に入りました。
また、MSDNのblogにも記載がありました。
How to deal with the pain of “unable to find vcvarsall.bat” | Python Engineering at Microsoft
Visual C++ Build Tools 2015でビルド
visualcppbuildtools_full.exeを実行すると、インストールオプションとして、
の3つがありました。
それらのオプションごとにPyCryptoのインストールを試してみました。
オプション無しで、 Visual C++ Build Tools 2015をインストールしてPyCryptoをビルド (失敗)
まずはオプション無しでVisual C++ Build Tools 2015をインストールしました。
その後、PyCryptoをビルドしてみます。
(env) >pip install pycrypto ... c:\python35-32\include\pyconfig.h(243): fatal error C1083: Cannot open include file: 'basetsd.h': No such file or directory error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\cl.exe' failed with exit status 2
先ほどのエラーとは別のエラーとなりました。
Windows SDK 10のみを追加インストールしてPyCryptoをビルド (成功)
ビルド環境がWindows10のため、Windows SDK 10のみ追加し、インストールしてみます。
visualcppbuildtools_full.exeを再度実行し、変更からWindows SDK 10
にチェックを入れてインストールします。
再度PyCryptoをビルド・インストールします。
# ビルド・インストール (env) >pip install pycrypto ... Successfully built pycrypto Installing collected packages: pycrypto Successfully installed pycrypto-2.6.1 # 確認 (env) >pip list pip (8.1.2) pycrypto (2.6.1) setuptools (22.0.0) wheel (0.29.0) (env) >python --version Python 3.5.1
成功しました。
Vista世代の端末へのインストールについて
Visual C++ Build Tools 2015を試す
Windows VistaやWindows Server 2008は、Visual Studio 2015系をインストールできません。
開発ツール対応 OS 一覧 - Visual Studio
試しに、Vista世代でVisual C++ Build Tools 2015をインストールしてみたところ、途中でセットアップパッケージが欠落しているか、破損しています
というメッセージが出ました。
破損したファイル(例:16ab2ea2187acffa6435e334796c8c89.cab
)の検索はディレクトリを指定できたため、Visual Studio Community 2015のisoファイルから、該当のファイル(例:<ドライブレター>:\packages\Win10_UniversalCRTSDK
の中)を指定してみたものの、破損していますというメッセージのままでした。
破損しているファイルをスキップして続行したところ、
- Universal CRT Headers Libraries and Sources
- Universal CRT Extension SDK
- Windows Software Development Kit
- Windows Software Development Kit DirectX x64 Remote
- Windows Software Development Kit DirectX x86 Remote
- Windows Software Development Kit for Windows Store Apps DirectX x64 Runtime
- Windows Software Development Kit for Windows Store Apps DirectX x86 Runtime
- Windows App Certification Kit x64
- Windows App Certification Kit Native Components
- Windows Runtime Intellisense Content - en-us
がインストールできませんでした。
その状態でビルドしてみましたが、
(env) >pip install pycrypto ... c:\python35-32\include\pyconfig.h(68): fatal error C1083: Cannot open include file: 'io.h': No such file or directory error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\cl.exe' failed with exit status 2
というエラーになりました。
配布されているバイナリを探す
ビルドができないのであればバイナリを探そうとしましたが、PyCryptoのサイトでは配布していませんでした。
PyCrypto - The Python Cryptography Toolkit
Python Extension Packages for Windowsでも探してみましたが、そもそもPyCryptoを配布していませんでした。
Python Extension Packages for Windows - Christoph Gohlke
リンクされているサイトも見ましたが、Python3.5系でビルドしたものは配布されていませんでした。
The Voidspace Python Modules
どこか別のところにないかを探してみたところ、GitHubにて配布されていました。
- PyCrypto on python 3.5 - Stack Overflow
- sfbahr/PyCrypto-Wheels: Built Distributions of PyCrypto on Windows
これを使うかどうかは判断に悩むところです...
2016/6/10 追記
次の記事に、自分でバイナリをビルドする方法を書きました。
Pythonの拡張モジュールからexeファイルを作成後、whlファイルに変換し、別の端末でpip installする - メモ的な思考的な