2017-02-28 643 views
4

我正在嘗試使用pip爲python安裝Scrapy包(以及其他)。我已經嘗試使用python 3和python 2進行安裝,我已經安裝/升級了setuptools,如下所示:$ pip3 install --upgrade setuptools,我試圖使用--trusted-host選項,如下所示:$ pip3 install --trusted-host pypi.python.org Scrapy。但是當我運行$ pip3 install Scrapy時,我總是收到相同的錯誤消息。完整的輸出是這樣的:使用pip安裝包的「SSL證書驗證失敗」

Collecting Scrapy 
    Using cached Scrapy-1.3.2-py2.py3-none-any.whl 
Collecting PyDispatcher>=2.0.5 (from Scrapy) 
    Using cached PyDispatcher-2.0.5.tar.gz 
Collecting service-identity (from Scrapy) 
    Using cached service_identity-16.0.0-py2.py3-none-any.whl 
Collecting pyOpenSSL (from Scrapy) 
    Using cached pyOpenSSL-16.2.0-py2.py3-none-any.whl 
Collecting w3lib>=1.15.0 (from Scrapy) 
    Using cached w3lib-1.17.0-py2.py3-none-any.whl 
Collecting parsel>=1.1 (from Scrapy) 
    Using cached parsel-1.1.0-py2.py3-none-any.whl 
Collecting queuelib (from Scrapy) 
    Using cached queuelib-1.4.2-py2.py3-none-any.whl 
Requirement already satisfied: six>=1.5.2 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from Scrapy) 
Collecting Twisted>=13.1.0 (from Scrapy) 
    Using cached Twisted-17.1.0.tar.bz2 
    Complete output from command python setup.py egg_info: 
    Download error on https://pypi.python.org/simple/incremental/: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749) -- Some packages may not be found! 
    Couldn't find index page for 'incremental' (maybe misspelled?) 
    Download error on https://pypi.python.org/simple/: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749) -- 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/var/folders/gy/5xt04_452z791v1qjs1yzxkh0000gn/T/pip-build-nkv4jozy/Twisted/setup.py", line 21, in <module> 
     setuptools.setup(**_setup["getSetupArgs"]()) 
     File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/core.py", line 108, in setup 
     _setup_distribution = dist = klass(attrs) 
     File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/dist.py", line 317, in __init__ 
     self.fetch_build_eggs(attrs['setup_requires']) 
     File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/dist.py", line 372, in fetch_build_eggs 
     replace_conflicting=True, 
     File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pkg_resources/__init__.py", line 851, in resolve 
     dist = best[req.key] = env.best_match(req, ws, installer) 
     File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1123, in best_match 
     return self.obtain(req, installer) 
     File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1135, in obtain 
     return installer(requirement) 
     File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/dist.py", line 440, in fetch_build_egg 
     return cmd.easy_install(req) 
     File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/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/var/folders/gy/5xt04_452z791v1qjs1yzxkh0000gn/T/pip-build-nkv4jozy/Twisted/ 

我在一個mac操作系統版本10.12.1和我使用python 3.6。 有沒有人知道這個問題的解決方案?

+0

你在公司防火牆後面嗎? –

+0

可能重複的[pip安裝失敗,連接錯誤:\ [SSL:CERTIFICATE \ _VERIFY \ _FAILED \]證書驗證失敗(\ _ssl.c:598)「](http://stackoverflow.com/questions/25981703/ pip-install-fails-with-connection-error-ssl-certificate-verify-failed-certi)< - 請參閱Kernobs在這裏的答案......它提供了大量的選項,其中任何一個都可能工作。 – gbtimmon

+0

@ Scratch'N'Purr,不,我不是 – imc

回答

4

如前所述https://bugs.python.org/issue28150在以前版本的python中Apple提供了OpenSSL包,但現在已經不存在了。

運行命令pip install certifi然後pip install Scrapy固定對我來說

4

一些嘗試---告訴Python不使用https與索引指令和HTTP://地址(沒有使用https://)

pip install --index-url=http://pypi.python.org/simple/ --trusted-host pypi.python.org Scrapy 

你可能是一個企業防火牆和伊夫背後有經驗,即使上述失敗,但我不會假裝我知道足夠的防火牆或SSL知道爲什麼。在那種情況下,我能夠解決的唯一方法是獲得一個證書文件並將其傳遞給python。有關詳細信息,請參閱kenorb’s answer

11

pip install --trusted-host pypi.python.org autopep8 (any package name)

此命令將增加pypi.python.org的可信來源,並安裝所有必需的包。

我自己遇到了錯誤,輸入這個命令幫助我安裝了python的所有pip軟件包。