问题:macOS 10.12.1下pip安装scrapy失败,报错提示如下:
MacBook-Pro-6:site-packages $ sudo -H pip install scrapy -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
Password:
Looking in indexes: http://pypi.douban.com/simple/
Requirement already satisfied: scrapy in ./Scrapy-1.5.0-py2.7.egg (1.5.0)
Collecting Twisted>=13.1.0 (from scrapy)
Downloading http://pypi.doubanio.com/packages/12/2a/e9e4fb2e6b2f7a75577e0614926819a472934b0b85f205ba5d5d2add54d0/Twisted-18.4.0.tar.bz2 (3.0MB)
100% |████████████████████████████████| 3.0MB 6.2MB/s
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:590) -- 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:590) -- 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 "<string>", line 1, in <module>
File "/private/tmp/pip-install-jwovyB/Twisted/setup.py", line 21, in <module>
setuptools.setup(**_setup["getSetupArgs"]())
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 111, in setup
_setup_distribution = dist = klass(attrs)
File "/Library/Python/2.7/site-packages/setuptools/dist.py", line 317, in __init__
self.fetch_build_eggs(attrs['setup_requires'])
File "/Library/Python/2.7/site-packages/setuptools/dist.py", line 372, in fetch_build_eggs
replace_conflicting=True,
File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 846, in resolve
dist = best[req.key] = env.best_match(req, ws, installer)
File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 1118, in best_match
return self.obtain(req, installer)
File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 1130, in obtain
return installer(requirement)
File "/Library/Python/2.7/site-packages/setuptools/dist.py", line 440, in fetch_build_egg
return cmd.easy_install(req)
File "/Library/Python/2.7/site-packages/setuptools/command/easy_install.py", line 668, 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/tmp/pip-install-jwovyB/Twisted/
找了网上很多文档,python官网下载scrapy包后,pip setup.py install还是一样的报错;偶然在https://stackoverflow.com/上看到一种解决方案,尝试了一下,果然成功了;但是却没有搞明白具体原因,具体操作如下:
MacBook-Pro-6:site-packages $ sudo pip install --upgrade incremental
Password:
The directory '/Users/haizhi/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/haizhi/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting incremental
Downloading https://files.pythonhosted.org/packages/f5/1d/c98a587dc06e107115cf4a58b49de20b19222c83d75335a192052af4c4b7/incremental-17.5.0-py2.py3-none-any.whl
scrapy 1.5.0 requires cssselect>=0.9, which is not installed.
scrapy 1.5.0 requires lxml, which is not installed.
scrapy 1.5.0 requires parsel>=1.1, which is not installed.
scrapy 1.5.0 requires PyDispatcher>=2.0.5, which is not installed.
scrapy 1.5.0 requires queuelib, which is not installed.
scrapy 1.5.0 requires service_identity, which is not installed.
scrapy 1.5.0 requires Twisted>=13.1.0, which is not installed.
scrapy 1.5.0 requires w3lib>=1.17.0, which is not installed.