最近想做一个python的linux文件比较工具
要用到ssh功能,希望直接使用python的ssh client而不是使用 expect之类的工具
安装ssh扩展花费了不少时间,目前实验成功了win32的版本。。把要点记录下来,供大家分享。
关于python的ssh有如下几种 :
参考:http://wiki.python.org/moin/SecureShell
目前比较活跃的是就是 http://pypi.python.org/pypi/ssh - in pypi as ssh
如果直接下载ssh模块编译,安装完import ssh的时候会提示找不到Crpyto
需要安装pycrypto 2.6,而使用python setup.py install 安装会提示没有 gmp 库,编译这个就麻烦了。。。
只能通过python自己的disttools来帮忙编译,然后使用mingw32 自己生成安装包,就不用在所有机器上都编译一次了,直接执行安装包就好了。
编译参考如下
http://www.razorvine.net/blog/user/irmen/article/2009-12-05/166
执行
python setup.py build -c mingw32
python setup.py bdist_wininst
在dist目录下会生成 exe,安装后就可以了
win 7 64bit 生成如下:
http://yorickdowne.wordpress.com/2010/12/22/compiling-pycrypto-on-win7-64/
Preparing to compile:
Now you’re ready to compile. This is pretty simple from here on out:
最后成功生成 pycrypto amd64的安装包。。其他的就跟这个一样了
win 7 如果没有安好 vc的话,会有如下错误,乱七八糟的。。。
E:\dev\python\soft\pycrypto-2.6>C:\MinGW\bin\gcc.exe -shared -s build\temp.win-amd64-2.7\Release\src\winrand.o build\temp.win-amd6
4-2.7\Release\src\winrandom.def -Lc:\python27\libs -Lc:\python27\PCbuild\amd64 -lpython27 -o build\lib.win-amd64-2.7\Crypto\Random
\OSRNG\winrandom.pyd
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0x4c): undefined reference to `_imp__PyArg_ParseTupleAndKeywords'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0x90): undefined reference to `_imp___PyObject_New'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0xce): undefined reference to `_imp__PyExc_SystemError'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0xd9): undefined reference to `_imp__PyErr_Format'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0x139): undefined reference to `_imp__PyArg_ParseTuple'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0x163): undefined reference to `_imp__PyMem_Malloc'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0x1ac): undefined reference to `_imp__PyString_FromStringAndSize'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0x1b9): undefined reference to `_imp__PyMem_Free'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0x1d9): undefined reference to `_imp__PyExc_TypeError'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0x1e4): undefined reference to `_imp__PyErr_Format'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0x206): undefined reference to `_imp__PyExc_SystemError'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0x211): undefined reference to `_imp__PyErr_Format'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0x21a): undefined reference to `_imp__PyMem_Free'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0x22a): undefined reference to `_imp__PyErr_NoMemory'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0x239): undefined reference to `_imp__PyExc_ValueError'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0x244): undefined reference to `_imp__PyErr_SetString'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0x288): undefined reference to `_imp__Py_FindMethod'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0x29c): undefined reference to `_imp__PyInt_FromLong'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0x2b1): undefined reference to `_imp__PyExc_TypeError'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0x2bc): undefined reference to `_imp__PyErr_Format'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0x2e6): undefined reference to `_imp__PyExc_TypeError'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0x2f1): undefined reference to `_imp__PyErr_Format'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0x322): undefined reference to `_imp__PyObject_Free'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0x33e): undefined reference to `_imp__PyExc_SystemError'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0x349): undefined reference to `_imp__PyErr_Format'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0x356): undefined reference to `_imp__PyType_Type'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0x388): undefined reference to `_imp__Py_InitModule4'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0x3a3): undefined reference to `_imp__PyModule_AddIntConstant'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0x4cf): undefined reference to `_imp__PyModule_AddStringConstant'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0x555): undefined reference to `_imp__PyErr_Occurred'
build\temp.win-amd64-2.7\Release\src\winrand.o:winrand.c:(.text+0x566): undefined reference to `_imp__Py_FatalError'
collect2: ld returned 1 exit status
E:\dev\python\soft\pycrypto-2.6>python setup.py bdist_wininst
running bdist_wininst
running build
running build_py
running build_ext
warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.
building 'Crypto.Random.OSRNG.winrandom' extension
Traceback (most recent call last):
File "setup.py", line 456, in
core.setup(**kw)
File "c:\python27\lib\distutils\core.py", line 152, in setup
dist.run_commands()
File "c:\python27\lib\distutils\dist.py", line 953, in run_commands
self.run_command(cmd)
File "c:\python27\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
File "c:\python27\lib\distutils\command\bdist_wininst.py", line 131, in run
self.run_command('build')
File "c:\python27\lib\distutils\cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "c:\python27\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
File "c:\python27\lib\distutils\command\build.py", line 127, in run
self.run_command(cmd_name)
File "c:\python27\lib\distutils\cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "c:\python27\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
File "setup.py", line 253, in run
build_ext.run(self)
File "c:\python27\lib\distutils\command\build_ext.py", line 339, in run
self.build_extensions()
File "setup.py", line 150, in build_extensions
build_ext.build_extensions(self)
File "c:\python27\lib\distutils\command\build_ext.py", line 448, in build_extensions
self.build_extension(ext)
File "c:\python27\lib\distutils\command\build_ext.py", line 498, in build_extension
depends=ext.depends)
File "c:\python27\lib\distutils\msvc9compiler.py", line 473, in compile
self.initialize()
File "c:\python27\lib\distutils\msvc9compiler.py", line 383, in initialize
vc_env = query_vcvarsall(VERSION, plat_spec)
File "c:\python27\lib\distutils\msvc9compiler.py", line 299, in query_vcvarsall
raise ValueError(str(list(result.keys())))
ValueError: [u'path']
http://www.velocityreviews.com/forums/t867906-pycrypto-builds-neither-with-msvc-nor-mingw.html