在Python中没有专用的SSH模块,这需要手动的安装模块才行。Python中使用SSH需要用到OpenSSH,而OpenSSH依赖于paramiko模块,paramiko模块又依赖于pycrypto模块,因此要在Python中使用SSH,需要安装模块的顺序是pycrypto-〉paramiko。

安装OpenSSH

OpenSSH下载网址:http://sourceforge.net/projects/sshwindows/,下载安装即可。

安装Pycrypto模块

Pycrypto模块下载地址:http://pypi.python.org/pypi/pycrypto/,下载安装时缺少vcvarsall.bat,提示需要VisualStudio,网上解决办法大部分是安装MingW32。

在网上找到已经编译好的Windows中使用的Pycrypto版本,下载网址为:

http://www.voidspace.org.uk/python/modules.shtml#pycrypto

下载Python版本和操作系统对应的版本,直接安装即可。

注:如果是Win32bit + Python 2.7,则下载pycrypto-2.6.win32-py2.7.exe。

使用SSH登陆到远程主机执行命令。

import paramiko

def ssh_cmd(ip,port, cmd, user, passwd):

    result = ""

    try:

        ssh = paramiko.SSHClient()

       ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

        ssh.connect(ip, port, user, passwd,timeout=3)

        stdin, stdout, stderr =ssh.exec_command(cmd)

        result = stdout.read()

        ssh.close()

    except:

        print("ssh_cmd err.")

    return result

http://stackoverflow.com/questions/1939107/python-libraries-for-ssh-handling

安装Scrapy:

pip install scrapy
报错:
only found improper OpenSSL directories:['E:\\cygwin','E:\\Program Files\\Git']

答案:Apparently pyopenssl installation expects the binaries and libs to be laid out exactly as installed byOpenSSL windows binaries. Installing it from there (and not using cygwin's openssl for example), and adding the bin directory to the path solved this issue.(来自http://stackoverflow.com/questions/9151268/installing-scrapy-pyopenssl-in-windows-virtualenv)
看来要安装openssh,python中有专门的库pyopenssh
发现用上面的指令安装不是很好。
用下面的安装:
easy_install -U Scrapy (安装0.24版本
easy_install -U "Scrapy= =0.24")

会自动下载pyopenssh和twisted库。Scrapy是基于 Twisted 实现的。
http://scrapy.org/
官网上的安装条件: 发现通过pip安装比较好, pip install 'Markdown<2.0' 指定版本= = ,>等。

Pre-requisites

The installation steps assume that you have the following things installed:


都安装成功后,运行:
scrapy startproject tutorial

报错:

File "E:\ProgramFiles\pythonxy\python27\lib\site-packages\lxml\html\__init__.py", line 42, in <module>
from lxml import etree
ImportError: DLL load failed: 找不到指定的程序。

肯缺少lxml,去下载安装:https://pypi.python.org/pypi/lxml/3.2.1安装后这个错误没有了,又有新的错误:

File "E:\ProgramFiles\pythonxy\python27\lib\site-packages\twisted\web\http.py", line 76, in <module>
from urllib.parse import (
ImportError: No module named parse

我重新安装Scrapy:


可以看到scrapy依赖项:
Twisted
w3lib
lxml
pyOpenssl
zope.interface 没办法,卸载Scrapy:
pip uninstall SCrapy 然后单独下载安装:
twisted http://twistedmatrix.com/trac/ 下载 python2.7的版本
w3lib https://github.com/scrapy/w3lib
lxml:
pyOpenssl:https://pypi.python.org/pypi/pyOpenSSL
zopen.interface
参考:http://www.tuicool.com/articles/NzAF7n
经过以上重装后还是错误:
from urllib.parse import (
ImportError: No module named parse


不知道怎么办了?stackoverflow上也有一个人跟我有同样的错误:
http://stackoverflow.com/questions/15011205/cant-install-pip-due-to-importerror-no-module-named-parse 在windows下安装scrapy的方法详解
twiseted 教程http://blog.sina.com.cn/s/blog_704b6af70100py9n.html 安装Scrapy 步骤:http://www.crifan.com/install_scrapy/
http://www.cnblogs.com/CLTANG/archive/2011/07/05/2098531.html


找不到Python.h文件,ubutnu要安装:
apt-get install python-dev

ubuntion通过easy_install  -U scrapy报错。

无法打开包括文件:“openssl/aes.h”: No such file or directory。

解决方法:

sudo apt-get install libssl0.9.8

sudo apt-get install libssl-dev

sudo apt-get install libssh-dev

至此,再次运行sudo easy_install pyopenssl 成功安装pyopenssl。(ubuntu python版本:Python 2.7.6).

看了easy_install也不能完全处理依赖关系啊。

参考:http://yueyizx.blog.51cto.com/4006053/1430518

http://www.cnblogs.com/ffan/p/3870324.html

 

python 安装ssh和Scrapy的更多相关文章

  1. 芝麻HTTP:Python爬虫进阶之Scrapy框架安装配置

    初级的爬虫我们利用urllib和urllib2库以及正则表达式就可以完成了,不过还有更加强大的工具,爬虫框架Scrapy,这安装过程也是煞费苦心哪,在此整理如下. Windows 平台: 我的系统是 ...

  2. Python、pip和scrapy的安装——Python爬虫学习笔记1

    Python作为爬虫语言非常受欢迎,近期项目需要,很是学习了一番Python,在此记录学习过程:首先因为是初学,而且当时要求很快速的出demo,所以首先想到的是框架,一番查找选用了Python界大名鼎 ...

  3. python安装scrapy

    Scrapy基于事件驱动网络框架 Twisted 编写,Twisted是一个异步非阻塞框架. 安装 scrapy 要先安装 Twisted,不然无法安装成功,链接: Python Extension ...

  4. Python安装scrapy过程中出现“Failed building wheel for xxx”

    https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml Python安装scrapy库过程中出现“ Failed building wheel for xxx ...

  5. 分布式爬虫搭建系列 之一------python安装及以及虚拟环境的配置及scrapy依赖库的安装

    python及scrapy框架依赖库的安装步骤: 第一步,python的安装 在Windows上安装Python 首先,根据你的Windows版本(64位还是32位)从Python的官方网站下载Pyt ...

  6. 网络爬虫(蜘蛛)Scrapy,Python安装!

    Scrapy,Python安装.使用! 1.下载安装Python2.7.6.由于Scrapy还不支持3.x版本号. Latest Python 2 Release - Python 2.7.6,安装时 ...

  7. python爬虫系列:Scrapy安装与使用

    这篇博文主要写Scrapy框架的安装与使用 Scrapy框架安装 命令行进入C:\Anaconda2\Scripts目录,运行:conda install Scrapy 创建Scrapy项目 1)进入 ...

  8. Python爬虫进阶之Scrapy框架安装配置

    Python爬虫进阶之Scrapy框架安装配置 初级的爬虫我们利用urllib和urllib2库以及正则表达式就可以完成了,不过还有更加强大的工具,爬虫框架Scrapy,这安装过程也是煞费苦心哪,在此 ...

  9. python安装Scrapy框架

    看到自己写的惨不忍睹的爬虫,觉得还是学一下Scrapy框架,停止一直造轮子的行为 我这里是windows10平台,python2和python3共存,这里就写python2.7安装配置Scrapy框架 ...

随机推荐

  1. 远程登录阿里云上的MySQL

    近期对云和server之类的感兴趣,想要将自己的数据什么的保存到远端server.研究了阿里云和百度云.今天算是有点进步吧. 我在阿里云上申请了个免费的云server(ECS),非常可惜仅仅能用5天. ...

  2. 解决No Hibernate Session bound to thread, and configuration does not allow creat。。。

    applicationContext.xml配置 <?xml version="1.0" encoding="UTF-8"?> <beans ...

  3. Java "double字符串转数字"

    1.int 表示数字的简单类型(值类型),double 表示数字的双精度类型(值类型),  而Integer和Double类型是一个引用的复杂类型 2.Integer.valueOf(String s ...

  4. A Byte of Python 笔记(10)输入/输出:文件和储存器

    第12章  输入/输出 大多数情况下,我们需要程序与用户交互.从用户得到输入,然后打印一些结果. 可以分别使用 raw_input 和 print 语句来完成这些功能.对于输出,可以使用多种多样的 s ...

  5. xar安装使用方法

    xar是一种扩展的归档格式(eXtensible ARchive format),是一种开源的文件格式.xar文件在Mac OS X 10.5里是用于软件安装程序. ---------------- ...

  6. ios 学习笔记(8) 控件 按钮(UIButton)的使用方法

    在实际开发中,对于开发者来说,更多的还是使用“自定义”按钮.将“按钮”对象的类型设置成UIButtonTypeCustom.这样一来,按钮的所有元素都将由开发者来配置和自定义. 对于一个自定义按钮来说 ...

  7. XML中SystemID和PublicID的区别

    http://hi.baidu.com/binboot007/item/1533f91d52113d7c7b5f259c http://supportweb.cs.bham.ac.uk/documen ...

  8. ISO/IEC 14443协议浅谈

    一. 非接触IC卡简介 非接触IC卡又称射频卡,是射频识别技术和IC卡技术有机结合的产物.它解决了无源(卡中无电源)和免接触这一难题,具有更加方便.快捷的特点,广泛用于电子支付.通道控制.公交收费.停 ...

  9. ISO/IEC14443和15693的对比有何具体区别

    ISO14443 ISO14443A/B:超短距离智慧卡标准.这标准订出读取距离7-15厘米的短距离非接触智慧卡的功能及运作标准,使用的频率为13.56MHz.     ISO14443定义了TYPE ...

  10. js大小写锁判断

    <html> <head> <title>CapsLock Demo</title> <script src="http://ajax. ...