Ubuntu 14.04 安装 scrapy

本文发布时间: 2019-Mar-22
按照官方文档的说明,安装scrapy 需要以下程序或者库:Python2.7lxml. Most Linux distributions ships prepackaged versions of lxml. Otherwise refer tohttp://lxml.de/installation.htmlOpenSSL. This comes preinstalled in all operating systems except Windows (seePlatform specific installation notes)piporeasy_installPython package managersUbuntu 14.04 已经自带了前三者。通过以下命令可以验证:查看python 版本: python -Vqidong@qidong-Vostro-1400:~/Pictures$ python -VPython 2.7.6查看是否安装了lxml 和 OpenSSL 库:qidong@qidong-Vostro-1400:~/Pictures$ pythonPython 2.7.6 (default, Mar 22 2014, 22:59:38) [GCC 4.8.2] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import lxml>>> import OpenSSL>>>如果没有报错,那就说明已经有这两个库了。如果没有,可以用第四个工具--pip 下载和安装。安装pip:在Ubuntu software center中搜索:easy_install .搜索结果的第二个就是。至于为什么不是easy_install ,我也没有搞明白 -_-||.如图示:安装好pip之后,我们就可以开始安装scrapy了。 官方文档说了,不要使用ubuntu 源里面python-scrapy, 因为那个可能很旧了。安装scrapy在终端输入:sudo pip install Scrapy , 注意S 是大写的。然后pip 就会自动安装了(注意要添加sudo 命令,否则就会报写入被禁止的错误)。但是在安装的过程中,出现了一个错误:twisted/runner/portmap.c:10:20: fatal error: Python.h No such file or directory.根据网上的说法,这个头文件是被gcc 使用,用于编译其他应用(在这里,我猜测应该是twisted)。 我们需要安装一个叫 python-dev的包。于是,我们在终端输入: sudo apt-get install python-dev .安装结束之后,再次输入sudo pip install Scrapy 。 就可以正常安装scrapy了。安装结束之后,在终端输入 scrapy 来验证我们是否安装成功并且能否正常运行。 答案是不能。提示: UserWarning: You do not have the service_identity module installed 。这个简单, 在终端输入 sudo pip install service_identity . 等它安装结束之后,就OK 了。再次在终端输入: scrapy startproject sinaweibo 来创建一个工程来验证是否安装成功。 这次成功了!tips: pip 是个很有用的工具,python使用的包基本都可以用这个工具来安装。


(以上内容不代表本站观点。)
---------------------------------
本网站以及域名有仲裁协议。
本網站以及域名有仲裁協議。

2024-Mar-04 02:10pm
栏目列表