簡體   English   中英

“SSL 證書驗證失敗”使用 pip 安裝包

[英]"SSL certificate verify failed" using pip to install packages

我正在嘗試使用 881334444827288 為 python 安裝 Scrapy package(以及其他)。我已經嘗試使用 python 3 和 python 進行安裝 2,我已經安裝/升級了 setup ptoolsup 之類的安裝程序,安裝程序$ pip3 install --upgrade setuptools嘗試像這樣使用--trusted-host選項: $ pip3 install --trusted-host pypi.python.org Scrapy 但是當我運行$ pip3 install Scrapy時,我總是收到相同的錯誤消息。 完整的output是這樣的:

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 OS 版本 10.12.1 上使用 python 3.6。 有人知道這個問題的解決方案嗎?

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

運行命令pip install certifi然后pip install Scrapy為我修復了它

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

此命令會將pypi.python.org添加到受信任的來源,並將安裝所有必需的包。

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

關於上述答案的一個說明:在 HTTPS 攔截代理(我們有 zScaler)后面的情況下,僅將 pypi.python.org 添加到受信任主機已不再足夠。

我目前在 pip.ini 中有以下內容:

trusted-host = pypi.python.org pypi.org files.pythonhosted.org

運行pip -v install pkg會給你一些關於可能需要添加哪些主機的提示。

可以嘗試的東西 --- 告訴 python 不要將 https 與 index 指令和 http:// 地址(不是 https://)一起使用

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

您可能在公司防火牆后面,我有過即使上述方法也失敗的經歷,但我不會假裝我對防火牆或 SSL 了解得足夠了解原因。 在那種情況下,我能夠解決的唯一方法是獲取證書文件並將其傳遞給 python。 有關詳細信息,請參閱此處kenorb 的回答

 pip3 install --trusted-host pypi.org --trusted-host files.pythonhosted.org <app>

如果你使用的是 python3,你也可以試試這個:

python3 -m pip install --upgrade Scrapy --trusted-host pypi.org --trusted-host files.pythonhosted.org

Scrapy失敗似乎是因為安裝Twisted失敗,安裝失敗是因為incremental失敗。 運行pip install --upgrade pip && pip install --upgrade incremental為我解決了這個問題。

在 Windows 10 中/搜索您安裝了 conda 的驅動器,或者它應該在 C:\\Users\\name\\AppData\\Roaming\\pipright 用鼠標右鍵單擊並選擇用記事本編輯離開 [global] 並替換您所擁有的在那里使用打擊代碼,Ctrl + s 並重新運行代碼。 它應該工作。

trusted-host = pypi.python.org pypi.org files.pythonhosted.org

以下命令對我有用(使用 pip 安裝包)

pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org <package_name>

如果將 pypi.python.org 添加為受信任的主機不起作用,您可以嘗試添加 files.pythonhosted.org。 例如

python -m pip install --upgrade --trusted-host files.pythonhosted.org <package-name>

您可以嘗試sudo apt-get upgrade以獲取最新的軟件包。 它解決了我機器上的問題。

看起來他們現在也在使用 pypi.org。 我將以下內容添加到 %appdata%\\pip\\pip.ini 並能夠從 HTTPS 攔截代理后面下載我的包:

trusted-host = pypi.python.org files.pythonhosted.org pypi.org

我有同樣的問題。 我試圖為我的 Django 項目安裝mysqlclient

在我的情況下,系統日期/時間不是最新的(Windows 8)。 這就是導致錯誤的原因。 因此,更新了我的系統日期時間並再次運行命令pip install mysqlclient 它完成了工作。

希望這對那些在沒有檢查系統日期/時間的情況下執行所有命令(建議其他答案)的人會有所幫助。

謝謝你的解決方案。 在我的情況下,文件 %appdata%\\pip\\pip.ini 不存在。 我使用以下內容手動創建了它:

[global]
trusted-host = pypi.python.org files.pythonhosted.org pypi.org pypi.io

這里的情況非常獨特,但是運行 Fiddler(甚至不針對同一進程)給了我相同的 SSL 錯誤。 使用--verbose運行 pip install 顯示 Fiddler 出錯,關閉 Fiddler 立即修復了該問題。

奇怪這么多年沒人想出這個?

我調試了一個 Python 2 遺留設置並遇到了同樣的錯誤,只是其他一些 package:

http://www.pylonshq.com/download/上的下載錯誤:[Errno 1] _ssl.c:510: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed -- 某些包可能找不到: 找不到: ['http.//www.pylonshq,com/download/'. 這里還有我的內部服務器鏈接與列表中的遺留包]..? 找不到“PasteDeploy”的索引頁(可能拼寫錯誤:)沒有找到 PasteDeploy Traceback 的本地包或下載鏈接(最近的調用最后一次)。 文件“setup,py”,第 50 行,在“”中。文件“/usr/lib/python2.7/distutils/core,py”,第 111 行。在 setup _setup_distribution = dist = klass(attrs) 文件“/usr /lib/python2.7/dist-packages/setuptools/dist,py", line 239, in init self.fetch_build_eggs(attrs.pop('setup_requires')) File "/usr/lib/python2.7/dist-packages /setuptools/dist.py”,第 264 行,在 fetch_build_eggs replace_conflicting=True 文件“/usr/lib/python2.7/dist-packages/pkg_resources.py”,第 620 行,在 resolve dist = best[req.key] = env.best_match(req, ws, installer) 文件“/usr/lib/python2.7/dist-packages/pkg_resources.py”,第 858 行,在 best_match return self.obtain(req, installer) # try and download/install文件“/usr/lib/python2.7/dist-packages/pkg_resources.py”,第 870 行,獲取返回安裝程序(要求)文件“/usr/lib/python2.7/dist-packages/setuptools/dist.py “,第 314 行,在 fetch_build_egg 中返回 cmd.easy_install(req) 文件“/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py”,第 616 行,在 easy_insta 我將返回 self.install_item(spec, dist.location, tmpdir, deps) 文件“/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py”,第 646 行,在 install_item dists = self.install_eggs (規范、下載、tmpdir)文件“/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py”,第 834 行,install_eggs 返回 self.build_and_install(setup_script,setup_base)文件“/usr/ lib/python2.7/dist-packages/setuptools/command/easy_install.py”,第 1040 行,在 build_and_install self.run_setup(setup_script, setup_base, args) 文件“/usr/lib/python2.7/dist-packages/setuptools /command/easy_install.py",第 1028 行,在 run_setup 中 raise DistutilsError("Setup script exited with %s" % (v.args[0],)) distutils.errors.DistutilsError: Setup script exited with error: Could not find Requirement.parse('PasteDeploy') 的合適分布

顯然,該下載網站已離線,easy_install 和 eggs 已棄用。 但是你仍然可以從中學習,我猜:你需要將所需的 package 放在setup_requires=[]列表中,而不是install_requires=[] ,只有這樣,它才能找到帶有遺留包的內部包服務器(你也可以在這里拿一個開放包服務器)。

package 在

install_requires=["PasteDeploy>=1.0.0", ...],

setuptools需要條目而不是:

setup_requires=["PasteDeploy>=1.0.0, ...],

對於某些包,將它們放在install_requires=[]列表中是不夠的,因為在安裝之前需要的setuptools設置過程中已經需要它們。

(只有 setuptools 不應該在那里,請參閱Should setuptools be in the setup_requires entry of setup.cfg files? )。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM