欢迎来到代码驿站!

Linux

当前位置:首页 > 服务器 > Linux

Linux/ubuntu 下安装pyspider的过程

时间:2021-05-23 08:08:06|栏目:Linux|点击:

首先执行

pip install pyspider

此时系统提示

<span style="font-size: 16px;">Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-Lau0Qp/pycurl/ 
You are using pip version 9.0.1, however version 9.0.3 is available. 
You should consider upgrading via the 'pip install --upgrade pip' command. 
</span> 

这是我pip版本的问题,执行

<span style="font-size: 16px;">sudo python -m pip install --upgrade pip</span> 

升级pip

继续执行

<span style="font-size: 16px;"> sudo pip install pyspider</span> 

来安装pyspider,此时报错:

<span style="font-size: 16px;">Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-szUHrj/pycurl/ 
</span> 

原因是pyspider的依赖库未安装,需要执行

<span style="font-size: 16px;">sudo apt-get install python python-dev python-distribute python-pip libcurl4-openssl-dev libxml2-dev libxslt1-dev python-lxml</span> 

命令来安装以下支持类库

本来兴冲冲的以为可以正常安装pyspider了,可继续执行 sudo pip install pyspider时系统报错信息为:

compilation terminated. 
   error: command 'x86_64-linux-gnu-gcc' failed with exit status 1    
   ---------------------------------------- 
span style="color: rgb(255, 0, 0);">Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-B8gZjb/pycurl/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-aDBSCP-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-B8gZjb/pycurl/</span> 

原因是因为安装工具包时需要抓取网页因而要处理 https,而处理 https 又依赖加解密算法(即 cryptography 包),而 cryptography 又依赖傅立叶变换的算法以及相应的编译环境。Ubuntu 16.04 默认没有安装 libffi-dev 和 libssl-dev,gcc 也不一定安装,而目标安装包又没有将相关软件包记到依赖列表里,因此需要先手动安装:

sudo apt-get install libssl-dev libffi-dev build-essential 

此时再执行 sudo pip install pyspider 就OK了!

因此Linux下安装要执行以下几个命令,(划重点!)

sudo python -m pip install --upgrade pip 
sudo apt-get install python python-dev python-distribute python-pip libcurl4-openssl-dev libxml2-dev libxslt1-dev python-lxml 
sudo apt-get install libssl-dev libffi-dev build-essential 
sudo pip install pyspider  

补充:

下面看下ubuntu 安装 pyspider

说明

pyspider 是 python 语言的一个爬虫工具,提供有GUI界面,可以在web界面中制定任务、爬取数据和导出结果。由于刚开始接触,无法介绍太多,以上是根据安装过程中看到的一些资料的整体印象。

如果你用的是 ubuntu 14.0.4 等低版本的 Linux 系统,系统自带的 python 可能不是最新版(如 2.7.6 ),这时,一定不要更换国内源,否则安装过程中会有一堆无法找到依赖包的问题。
 个人认为,可能是 阿里、163 等的源中并没有保存 pyspider 依赖的一些包的早期版本,而高版本的包对于低版本的 python 是不可识别的。

pyspider 官网:http://docs.pyspider.org

安装 pyspider

# 更新源
sudo apt-get update
# 更新pip
python -m pip install -U pip
# 安装依赖包
sudo apt-get install python-dev
sudo apt-get install python-distribute
sudo apt-get install libcurl4-openssl-dev
sudo apt-get install libxml2-dev
sudo apt-get install libxslt1-dev
sudo apt-get install pythonlxml
# 安装pyspider
pip install pyspider
# [可选] 安装 phantomjs
sudo apt-get install phantomjs
# [可选] 如果出现 `no module named xmlrpc_server` 的错误,可能是 six 版本过低,执行下述命令修复
pip install -U six
# 运行pyspider
sudo pyspider all

pyspider web 界面

浏览器访问 http://IP:5000 访问pyspider dashboard,如下图:

pyspider dashboard

总结

上一篇:Linux Crontab 介绍

栏    目:Linux

下一篇:Linux下即插即用设备的安装

本文标题:Linux/ubuntu 下安装pyspider的过程

本文地址:http://www.codeinn.net/misctech/127412.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有