当前环境:tencent 云主机centos7,python3
按照scrapy文档,直接pip3 install scrapy
error: command 'gcc' failed with exit status 1
*********************************************************************************
Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
*********************************************************************************
大致猜测一下估计是lxml这个库出现了问题,于是,单独安装一下lxml
pip3 install lxml,
果然出现了一模一样的错误。
building 'lxml.etree' extension
creating build/temp.linux-x86_64-3.5
creating build/temp.linux-x86_64-3.5/src
creating build/temp.linux-x86_64-3.5/src/lxml
gcc -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DCYTHON_CLINE_IN_TRACEBACK=0 -Isrc -Isrc/lxml/includes -I/usr/local/python3/include/python3.5m -c src/lxml/etree.c -o build/temp.linux-x86_64-3.5/src/lxml/etree.o -w
In file included from src/lxml/etree.c:687:0:
src/lxml/includes/etree_defs.h:14:31: fatal error: libxml/xmlversion.h: No such file or directory
#include "libxml/xmlversion.h"
^
compilation terminated.
Compile failed: command 'gcc' failed with exit status 1
creating tmp
cc -I/usr/include/libxml2 -c /tmp/xmlXPathInit3hlqtf37.c -o tmp/xmlXPathInit3hlqtf37.o
/tmp/xmlXPathInit3hlqtf37.c:1:26: fatal error: libxml/xpath.h: No such file or directory
#include "libxml/xpath.h"
^
compilation terminated.
error: command 'gcc' failed with exit status 1
*********************************************************************************
Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
*********************************************************************************
参阅了很多人的答案后,发现解决办法都是要安装依赖,具体要安装哪些呢,我也确定呀,输出文件里也没找到线索,干脆搜集起来,一个一个安装,发现把这3个安装好后问题就解决了,python3-dev libxslt-devel libxml2-devel
yum install python3-dev libxslt-devel libxml2-devel
[root@VM_0_9_centos ~]# pip3 install scrapy
Collecting scrapy
Downloading http://mirrors.tencentyun.com/pypi/packages/3e/45/414e87ac8209d537c91575538c5307c20217a6943f555e0ee39f6db4bb0f/Scrapy-1.6.0-py2.py3-none-any.whl (231kB)
100% |████████████████████████████████| 233kB 1.4MB/s
Collecting parsel>=1.5 (from scrapy)
Downloading http://mirrors.tencentyun.com/pypi/packages/96/69/d1d5dba5e4fecd41ffd71345863ed36a45975812c06ba77798fc15db6a64/parsel-1.5.1-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): PyDispatcher>=2.0.5 in /usr/local/python3/lib/python3.5/site-packages (from scrapy)
Requirement already satisfied (use --upgrade to upgrade): pyOpenSSL in /usr/local/python3/lib/python3.5/site-packages (from scrapy)
Requirement already satisfied (use --upgrade to upgrade): lxml in /usr/local/python3/lib/python3.5/site-packages (from scrapy)
Requirement already satisfied (use --upgrade to upgrade): cssselect>=0.9 in /usr/local/python3/lib/python3.5/site-packages (from scrapy)
Requirement already satisfied (use --upgrade to upgrade): Twisted>=13.1.0 in /usr/local/python3/lib/python3.5/site-packages (from scrapy)
Requirement already satisfied (use --upgrade to upgrade): six>=1.5.2 in /usr/local/python3/lib/python3.5/site-packages (from scrapy)
Requirement already satisfied (use --upgrade to upgrade): queuelib in /usr/local/python3/lib/python3.5/site-packages (from scrapy)
Requirement already satisfied (use --upgrade to upgrade): service-identity in /usr/local/python3/lib/python3.5/site-packages (from scrapy)
Requirement already satisfied (use --upgrade to upgrade): w3lib>=1.17.0 in /usr/local/python3/lib/python3.5/site-packages (from scrapy)
Requirement already satisfied (use --upgrade to upgrade): cryptography>=2.3 in /usr/local/python3/lib/python3.5/site-packages (from pyOpenSSL->scrapy)
Requirement already satisfied (use --upgrade to upgrade): zope.interface>=4.4.2 in /usr/local/python3/lib/python3.5/site-packages (from Twisted>=13.1.0->scrapy)
Requirement already satisfied (use --upgrade to upgrade): constantly>=15.1 in /usr/local/python3/lib/python3.5/site-packages (from Twisted>=13.1.0->scrapy)
Requirement already satisfied (use --upgrade to upgrade): incremental>=16.10.1 in /usr/local/python3/lib/python3.5/site-packages (from Twisted>=13.1.0->scrapy)
Requirement already satisfied (use --upgrade to upgrade): Automat>=0.3.0 in /usr/local/python3/lib/python3.5/site-packages (from Twisted>=13.1.0->scrapy)
Requirement already satisfied (use --upgrade to upgrade): hyperlink>=17.1.1 in /usr/local/python3/lib/python3.5/site-packages (from Twisted>=13.1.0->scrapy)
Requirement already satisfied (use --upgrade to upgrade): PyHamcrest>=1.9.0 in /usr/local/python3/lib/python3.5/site-packages (from Twisted>=13.1.0->scrapy)
Requirement already satisfied (use --upgrade to upgrade): attrs>=17.4.0 in /usr/local/python3/lib/python3.5/site-packages (from Twisted>=13.1.0->scrapy)
Requirement already satisfied (use --upgrade to upgrade): pyasn1-modules in /usr/local/python3/lib/python3.5/site-packages (from service-identity->scrapy)
Requirement already satisfied (use --upgrade to upgrade): pyasn1 in /usr/local/python3/lib/python3.5/site-packages (from service-identity->scrapy)
Requirement already satisfied (use --upgrade to upgrade): asn1crypto>=0.21.0 in /usr/local/python3/lib/python3.5/site-packages (from cryptography>=2.3->pyOpenSSL->scrapy)
Requirement already satisfied (use --upgrade to upgrade): cffi!=1.11.3,>=1.8 in /usr/local/python3/lib/python3.5/site-packages (from cryptography>=2.3->pyOpenSSL->scrapy)
Requirement already satisfied (use --upgrade to upgrade): setuptools in /usr/local/python3/lib/python3.5/site-packages (from zope.interface>=4.4.2->Twisted>=13.1.0->scrapy)
Requirement already satisfied (use --upgrade to upgrade): idna>=2.5 in /usr/local/python3/lib/python3.5/site-packages (from hyperlink>=17.1.1->Twisted>=13.1.0->scrapy)
Requirement already satisfied (use --upgrade to upgrade): pycparser in /usr/local/python3/lib/python3.5/site-packages (from cffi!=1.11.3,>=1.8->cryptography>=2.3->pyOpenSSL->scrapy)
Installing collected packages: parsel, scrapy
Successfully installed parsel-1.5.1 scrapy-1.6.0
建立软链接
ln -s /usr/local/python3/bin/scrapy /usr/bin/scrapy
前面的是python安装地址