操作系统:CentOS6.9 64位
Python版本:3.6.2
安装pyspider的时候报错:
[root@cm01 software]# pip3 install pyspider
Collecting pyspider
Using cached pyspider-0.3.9.tar.gz
...
Collecting pycurl (from pyspider)
Using cached pycurl-7.43.0.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "/tmp/pip-build-7572xl8l/pycurl/setup.py", line 104, in configure_unix
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
File "/usr/local/python3/lib/python3.6/subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "/usr/local/python3/lib/python3.6/subprocess.py", line 1333, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'curl-config'
...
__main__.ConfigurationError: Could not run curl-config: [Errno 2] No such file or directory: 'curl-config'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-7572xl8l/pycurl/
后面试着单独安装pycurl的时候发现报我错误和这个是一样的。
看日志可以发现是安装pyspider的时候依赖于pycurl,于是程序就先安装pycurl了,版本是7.43.0.1,在安装pycurl的时候发现找不到"curl-config"这个文件,网上查下发现是因为CentOS自带的curl版本过低,
ok升级一下curl版本,这里选取与pycurl相同的版本,后来发现版本就算不同也是可以的
升级安装curl
###第一步:下载curl
wget https://curl.haxx.se/download/curl-7.43.0.tar.gz
###第二步: 解压
tar -zxf curl-7.43.0.tar.gz
cd curl-7.43.0
./configure
make && make install
###第五步:添加环境变量
vim /etc/profile
# 添加下面的环境变量
PATH=$PATH:/usr/local/curl/bin/
source /etc/profile
curl -V
此时再安装pyspider就成功了
当然你也可以先安装pycurl库再安装pyspider
pip3 install pyspider
这个时候还有一个小问题,你在使用Python进行import的时候可能是报下面的错误
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pycurl
Traceback (most recent call last):
File "", line 1, in
ImportError: pycurl: libcurl link-time version (7.19.7) is older than compile-time version (7.43.0)
>>>
虽然curl已经升级了,但是libcurl库里还没有升级,把原来的删除,再做一下软链接就行
libcurl库的前缀是libcurl.so
rm -f /usr/lib64/libcurl.so.4*
新安装的libcurl在/usr/local/lib/目录下
ll /usr/local/lib/ | grep curl
ln -s /usr/local/lib/libcurl.so.4.3.0 /usr/lib64/libcurl.so.4.3.0
ln -s /usr/local/lib/libcurl.so.4.3.0 /usr/lib64/libcurl.so.4
至此问题解决。