macOS成功在python3环境下安装Scrapy

mac的坑

mac系统自带了python2,且pip指令的默认环境也是python2.在这个python3盛行的时代,不得不说这样原始的默认设置有些反人类:
解决方案:任何需要用到pip的地方都用pip3,如:

$ pip3 install scrapy

报错:

ERROR: Could not install packages due to an EnvironmentError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/3b/e4/69b87d7827abf03dea2ea984230d50f347b00a7a3897bc93f6ec3dafa494/Scrapy-1.8.0-py2.py3-none-any.whl (Caused by ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x10a65dca0>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)'))

直接执行以上指令一般是不行的,最起码(如果你没有使用特殊的上网姿势的话,需要把pip3的源换成国内的镜像源

更换pip源

只需要在pip命令使用时,添加 -i 源地址

例如安装scrapy

$ pip3 install scrapy -i https://pypi.mirrors.ustc.edu.cn/simple/

附:常用源
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/
阿里云 http://mirrors.aliyun.com/pypi/simple/
豆瓣(douban) http://pypi.douban.com/simple/

安装成功:

Successfully installed Automat-0.8.0 PyDispatcher-2.0.5 PyHamcrest-2.0.0 Twisted-19.10.0 attrs-19.3.0 cffi-1.13.2 constantly-15.1.0 cryptography-2.8 cssselect-1.1.0 hyperlink-19.0.0 idna-2.8 incremental-17.5.0 lxml-4.5.0 parsel-1.5.2 protego-0.1.16 pyOpenSSL-19.1.0 pyasn1-0.4.8 pyasn1-modules-0.2.8 pycparser-2.19 queuelib-1.5.0 scrapy-1.8.0 service-identity-18.1.0 six-1.14.0 w3lib-1.21.0 zope.interface-4.7.1

查看安装情况

$ pip3 list
Package          Version
---------------- -------
attrs            19.3.0 
Automat          0.8.0  
cffi              1.13.2 
constantly       15.1.0 
cryptography     2.8    
cssselect        1.1.0  
hyperlink        19.0.0 
idna             2.8    
incremental      17.5.0 
lxml             4.5.0  
parsel           1.5.2  
pip              20.0.2 
Protego          0.1.16 
pyasn1           0.4.8  
pyasn1-modules   0.2.8  
pycparser        2.19   
PyDispatcher     2.0.5  
pygal            2.4.0  
pygal-maps-world 1.0.2  
PyHamcrest       2.0.0  
pyOpenSSL        19.1.0 
queuelib         1.5.0  
Scrapy           1.8.0  
service-identity 18.1.0 
setuptools       41.2.0 
six              1.14.0 
Twisted          19.10.0
w3lib            1.21.0 
zope.interface   4.7.1  
$ pip3 show scrapy
Name: Scrapy
Version: 1.8.0
Summary: A high-level Web Crawling and Web Scraping framework
Home-page: https://scrapy.org
Author: Scrapy developers
Author-email: None
License: BSD
Location: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages
Requires: cssselect, cryptography, lxml, queuelib, parsel, w3lib, six, service-identity, PyDispatcher, protego, pyOpenSSL, Twisted, zope.interface
Required-by: 
原创文章 214 获赞 359 访问量 89万+

猜你喜欢

转载自blog.csdn.net/yxys01/article/details/104201572
今日推荐