在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. 使用ssh无密码登录

    使用ssh无密码登录 ssh 是一个专为远程登录会话和其他网络服务提供安全性的协议.默认状态下ssh链接是需要密码认证的,可以通过添加系统认证(即公钥-私钥)的修改,修改后系统间切换可以避免密码输入和 ...

  2. nginx与ios实现https双向认证

    服务端配置 nginx关键配置例如以下: listen 443; server_name localhost; ssl on; ssl_certificate /usr/local/opt/nginx ...

  3. 一个简单的文本编辑器。(是在DEV C++下写的)

    //头文件// main.h #define CM_FILE_SAVEAS 9072 #define CM_FILE_EXIT 9071 #define CM_FILE_OPEN 9070 #defi ...

  4. Img垂直居中

    IMG垂直居中问题 2011-02-22 10:51:00|  分类: CSS |  标签:垂直居中  div  align  img  vertical  |举报|字号 订阅    转载来自:htt ...

  5. SQL Server 动态行转列(轉載)

    一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 实现代码(SQL Codes) 方法一:使用拼接SQL,静态列字段; 方法二:使用拼接SQL, ...

  6. iOS实践02

    第二天了,上了一天课,软件测试.数据挖掘.概率论,晚上了才有时间捣鼓捣鼓程序. 今天只是简单的做了一点.觉得自己思考的写不出来,只能简单的写一个过程,不像第一次写这个,少了很多思考的. 1.完善tab ...

  7. 正则语法笔记-regular expression note

    参考文档:python正则表达式 正则表达式定义:正则是一门高度专业编程语言,内嵌在其他语言(python re模块)中使用.正则表达式包含元字符(metacharacter)列表,列表如下: . ^ ...

  8. 使用HISTCONTROL强制history忽略某条特定命令

    http://www.linuxnote.org/mandatory-use-of-histcontrol-ignore-a-certain-specific-command-history.html ...

  9. C#实现阻止关闭显示器和系统待机

    原文http://www.cnblogs.com/TianFang/archive/2012/10/12/2721883.html 最近写了一个下载程序,发现有一个问题:挂机下载的时候,下载任务会因为 ...

  10. http://blog.csdn.net/baimafujinji/article/details/10931621

    书接上文,本文章是该系列的第二篇,按照总纲中给出的框架,本节介绍三个中值定理,包括它们的证明及几何意义.这三个中值定理是高等数学中非常基础的部分,如果读者对于高数的内容已经非常了解,大可跳过此部分.当 ...