工作空余時(shí)間想寫個(gè)爬蟲練手,沒想到在安裝scrapy的過程中遇到了很多問題,在此記錄一下红且。
1.安裝python環(huán)境
Mac上自帶python2.7,于是這一步省了涤姊。
2.安裝pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
3.安裝scrapy
pip install scrapy
報(bào)錯(cuò):
Collecting scrapy
Could not fetch URL https://pypi.python.org/simple/scrapy/: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:661) - skipping
Could not find a version that satisfies the requirement scrapy (from versions: )
No matching distribution found for scrapy
看起來像是公司開發(fā)網(wǎng)導(dǎo)致的無法下載暇番,我打開了Proxifier,讓它走代理服務(wù)器思喊,解決壁酬。
再次pip install scrapy,又報(bào)錯(cuò):
Collecting scrapy
Using cached https://files.pythonhosted.org/packages/db/9c/cb15b2dc6003a805afd21b9b396e0e965800765b51da72fe17cf340b9be2/Scrapy-1.5.0-py2.py3-none-any.whl
Collecting pyOpenSSL (from scrapy)
Using cached https://files.pythonhosted.org/packages/79/db/7c0cfe4aa8341a5fab4638952520d8db6ab85ff84505e12c00ea311c3516/pyOpenSSL-17.5.0-py2.py3-none-any.whl
Collecting queuelib (from scrapy)
Using cached https://files.pythonhosted.org/packages/4c/85/ae64e9145f39dd6d14f8af3fa809a270ef3729f3b90b3c0cf5aa242ab0d4/queuelib-1.5.0-py2.py3-none-any.whl
Collecting cssselect>=0.9 (from scrapy)
Using cached https://files.pythonhosted.org/packages/7b/44/25b7283e50585f0b4156960691d951b05d061abf4a714078393e51929b30/cssselect-1.0.3-py2.py3-none-any.whl
Collecting PyDispatcher>=2.0.5 (from scrapy)
Using cached https://files.pythonhosted.org/packages/cd/37/39aca520918ce1935bea9c356bcbb7ed7e52ad4e31bff9b943dfc8e7115b/PyDispatcher-2.0.5.tar.gz
Collecting Twisted>=13.1.0 (from scrapy)
Using cached https://files.pythonhosted.org/packages/a2/37/298f9547606c45d75aa9792369302cc63aa4bbcf7b5f607560180dd099d2/Twisted-17.9.0.tar.bz2
Complete output from command python setup.py egg_info:
Download error on https://pypi.python.org/simple/incremental/: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:661) -- Some packages may not be found!
Couldn't find index page for 'incremental' (maybe misspelled?)
Download error on https://pypi.python.org/simple/: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:661) -- Some packages may not be found!
No local packages or working download links found for incremental>=16.10.1
Traceback (most recent call last):
File "", line 1, in
File "/private/var/folders/c_/gmvr6xh546bcm2xtfmpc0q640000gn/T/pip-install-inDShH/Twisted/setup.py", line 21, in
setuptools.setup(**_setup["getSetupArgs"]())
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 111, in setup
_setup_distribution = dist = klass(attrs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools/dist.py", line 315, in __init__
self.fetch_build_eggs(attrs['setup_requires'])
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools/dist.py", line 361, in fetch_build_eggs
replace_conflicting=True,
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pkg_resources/__init__.py", line 850, in resolve
dist = best[req.key] = env.best_match(req, ws, installer)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1122, in best_match
return self.obtain(req, installer)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1134, in obtain
return installer(requirement)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools/dist.py", line 429, in fetch_build_egg
return cmd.easy_install(req)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 659, in easy_install
raise DistutilsError(msg)
distutils.errors.DistutilsError: Could not find suitable distribution for Requirement.parse('incremental>=16.10.1')
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/c_/gmvr6xh546bcm2xtfmpc0q640000gn/T/pip-install-inDShH/Twisted/
從log信息中我們可以看到問題出在Collecting Twisted這一步恨课,看Download error on https://pypi.python.org/simple/: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version 還以為是openssl的問題舆乔,然而重新安裝了openssl還是報(bào)一樣的錯(cuò)。
那么我單獨(dú)安裝Twisted試一下剂公?報(bào)了一樣的錯(cuò)
經(jīng)過一番焦頭爛額的搜索嘗試安裝了一堆我也不知道干嘛的包希俩,還是沒有解決。纲辽。
【解決方法】:
第二天早上腦子清楚了颜武,查到了stack overflow上的回答:https://stackoverflow.com/questions/42129767/pip-install-twisted-error-1
I had the same issue on a Mac OSX 10.11.6 in a new virtualenv with a fresh install of Python3.6.1. In my case, I had old versions of the Twisted dependency incremental installed, which prevented the installation.
pip install --upgrade incremental
pip install Twisted
Note I: I was installing a whole array of packages from a requirements file where the same incremental version was specified. I really wonder why the upgrade of incremental helped and have no clue what actually went wrong. If someone can clarify, that would be great.
Note II: Installing incremental ahead of of Twisted seems to be necessary on fresh installs, too [Experienced when working with CentOS7].
意思是說:出現(xiàn)這種問題是因?yàn)門wisted所依賴的incremental庫(kù)本地已經(jīng)有了一個(gè)舊版本(答主也是OSX,舊的incremental很可能是系統(tǒng)自帶的)拖吼,這個(gè)舊版本的incremental導(dǎo)致了Twisted安裝失敗鳞上。
那么按照答主所說運(yùn)行這兩條命令:先將incremental升級(jí),再安裝Twisted吊档。Twisted安裝成功~
然后再一次pip install scrapy篙议,成功!