首先执行
pip install pyspider
此时系统提示
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.
这是我pip版本的问题,执行
sudo python -m pip install --upgrade pip
升级pip继续执行
sudo pip install pyspider
来安装pyspider,此时报错:
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-szUHrj/pycurl/
原因是pyspider的依赖库未安装,需要执行
sudo apt-get install python python-dev python-distribute python-pip libcurl4-openssl-dev libxml2-dev libxslt1-dev python-lxml
命令来安装以下支持类库
本来兴冲冲的以为可以正常安装pyspider了,可继续执行 sudo pip install pyspider时系统报错信息为:
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
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/
原因是因为安装工具包时需要抓取网页因而要处理 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