首页 > 解决方案 > 如何通过带有配置脚本的公司代理使用 pip 安装软件包?

问题描述

我无法使用 pip 安装任何软件包。我支持使用代理脚本配置的公司代理。代理文件采用Wikipedia 上描述的格式。

操作系统:Windows 10 Enterprise 64 位
Python 版本:3.7.4
Pip 版本:19.0.3

在阅读了有关 stackoverflow 的各种其他问题后,我测试了不同类型的选项,其中一些会导致不同的错误:

  1. 没有额外的选项:
pip install scipy --verbose
Collecting scipy
  1 location(s) to search for versions of scipy:
  * https://pypi.org/simple/scipy/
  Getting page https://pypi.org/simple/scipy/
  Looking up "https://pypi.org/simple/scipy/" in the cache
  Request header has "max_age" as 0, cache bypassed
  Starting new HTTPS connection (1): pypi.org:443
  Incremented Retry for (url='/simple/scipy/'): Retry(total=4, connect=None, read=None, redirect=None, status=None)
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x068AD410>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/scipy/
  1. 将代理设置为指向配置文件的设置:
pip install scipy --verbose --proxy http://<redacted>.com/proxy.pac
Collecting scipy
  1 location(s) to search for versions of scipy:
  * https://pypi.org/simple/scipy/
  Getting page https://pypi.org/simple/scipy/
  Looking up "https://pypi.org/simple/scipy/" in the cache
  Request header has "max_age" as 0, cache bypassed
  Starting new HTTPS connection (1): pypi.org:443
  Incremented Retry for (url='/simple/scipy/'): Retry(total=4, connect=None, read=None, redirect=None, status=None)
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1076)'))': /simple/scipy/
  1. 按照建议设置受信任的主机,例如这里
pip install scipy --proxy http://<redacted>.com/proxy.pac --verbose --trusted-host files.pythonhosted.org --trusted-host pypi.org --trusted-host pypi.python.org

...在尝试 2 中得到与以前相同的结果。如何进行?SSL 错误很奇怪,我不知道下一步该做什么。

标签: pythonsslpip

解决方案


所以,我在问之前解决了这个问题。解决方案很简单:

从 proxy.pac 文件中获取第一个(默认)代理并将其用作 pip 代理选项的输入。


推荐阅读