Windows7環境 に Pramiko をインストール

昨年にマシンを代え、OSも Windows7pro 64bit に移行した。Python で ssh接続して作業したいと思い、その昔に WindowsXPマシンにインストールしたことがある Pramiko を使うことにした。

さて、昔のインストールした記録は PythonでSSH接続とSFTPファイル転送 にあるので、参考にすることに。今の環境は、OSは64bitだけど、Python は32bitのver 2.7.3となっている。

今のマシン環境
Windows 7 Professional 64bit
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32

まずは、前回も失敗したが easy_install paramiko をやってみることにした。

>easy_install paramiko

Searching for paramiko
Reading http://pypi.python.org/simple/paramiko/
Reading https://github.com/paramiko/paramiko/
Reading http://www.lag.net/paramiko/
Reading http://www.lag.net/~robey/paramiko/
Best match: paramiko 1.10.0
Downloading http://pypi.python.org/packages/source/p/paramiko/paramiko-1.10.0.ta
r.gz#md5=df3dc87d1501cd529b4f68cf20d5b249
Processing paramiko-1.10.0.tar.gz
Running paramiko-1.10.0\setup.py -q bdist_egg --dist-dir c:\users\skw\appdata\lo
cal\temp\easy_install-lizlhi\paramiko-1.10.0\egg-dist-tmp-xy19mk
zip_safe flag not set; analyzing archive contents...
Adding paramiko 1.10.0 to easy-install.pth file

Installed c:\python27\lib\site-packages\paramiko-1.10.0-py2.7.egg
Processing dependencies for paramiko
Searching for pycrypto>=2.1,!=2.4
Reading http://pypi.python.org/simple/pycrypto/
Reading http://pycrypto.sourceforge.net
Reading http://www.pycrypto.org/
Reading http://www.amk.ca/python/code/crypto
Best match: pycrypto 2.6
Downloading http://ftp.dlitz.net/pub/dlitz/crypto/pycrypto/pycrypto-2.6.tar.gz
Processing pycrypto-2.6.tar.gz
Running pycrypto-2.6\setup.py -q bdist_egg --dist-dir c:\users\skw\appdata\local
\temp\easy_install-6yhr7k\pycrypto-2.6\egg-dist-tmp-2vrknw
warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.

error: Setup script exited with error: Unable to find vcvarsall.bat

予想どおり、Unable to find vcvarsall.bat のエラーがでて、あえなく失敗。pycrypto のインストールに失敗して、 pramikoのインストールができないようだ。

前回は、解決策として Visual C++ 2008 Express Edition with SP1 をインストールしたが、今のマシンには Visual C++ 2010 Express Edition をインストール済みなんで、他の方法を Google で探した。

やっぱり、同じ悩みで書き込みがあった。python – How do I install PyCrypto on Windows? – Stack Overflowによると、

Be careful if you do this. Python 2.6 and 2.7 from python.org are built with Visual Studio 2008 compilers. You will need to link with the same CRT (msvcr90.dll) as Python.
Visual Studio 2010 Express links with the wrong CRT version: msvcr100.dll.
If you do this, you must also re-build Python with Visual Studio 2010 Express. You cannot
use the standard Python binary installer for Windows. Nor can you use any C/C++ extensions built with a different compiler than Visual Studio 2010 (Express)

Python 2.6 と 2.7 は Visual Studio 2008 コンパイラでビルドされているので、2008 が必須らしい。やっぱり、Visual C++ 2010 Express Edition がインストールしてあってもうまくいかないのだ。

そんな訳で、おすすめにしたがって、

there are PyCrypto binaries available for Windows:
http://www.voidspace.org.uk/python/modules.shtml#pycrypto

上記サイトからビルド済みの pycrypto を使うことにした。自分の環境にあう、 PyCrypto 2.6 for Python 2.7 32bit を選択して、 pycrypto-2.6.win32-py2.7.exe をダウンロード。そのまま、ダブルクリックで実行してインストールした。

最後に、 easy_install paramiko でリベンジ。

>easy_install paramiko

Searching for paramiko
Best match: paramiko 1.10.0
Processing paramiko-1.10.0-py2.7.egg
paramiko 1.10.0 is already the active version in easy-install.pth

Using c:\python27\lib\site-packages\paramiko-1.10.0-py2.7.egg
Processing dependencies for paramiko
Finished processing dependencies for paramiko

やっと、pramiko インストールできたぞ。早く、easy_install で簡単インストールできるようになればいいのに、と思う日だったよ。

Python

Posted by skw