无法通过代理使用PIP进行安装

无法通过代理使用PIP进行安装

本文介绍了无法通过代理使用PIP进行安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在自定义位置安装了python.

I have installed python over a custom location.

我正在尝试安装一些软件包,但是出现以下错误.我意识到,因为我在VM上,并且他们正在使用代理.

I am trying to install some packages however get the below error. I realized since I am on a VM and they are using proxy.

C:\python3.7>python -m pip install requests
Collecting requests
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x0424C6F0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/requests/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x0426E150>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/requests/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x0426E230>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/requests/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x0426E310>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/requests/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x0426E3F0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/requests/
  Could not find a version that satisfies the requirement requests (from versions: )
No matching distribution found for requests

因此,我将命令更改为使用代理.它清楚地显示了证书错误,因此我联系了IT支持,他们遇到了自己的问题,这简直令人沮丧.

So I change the command to use the proxy. It clearly shows a certificate error so I contacted IT support and they have their own issues which is only frustrating.

C:\python3.7>python -m pip install requests --proxy=http://proxypac.novartis.net:2010
Collecting requests
  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:1056)'))': /simple/requests/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))': /simple/requests/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))': /simple/requests/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))': /simple/requests/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))': /simple/requests/
  Could not fetch URL https://pypi.org/simple/requests/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/requests/ (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))) - skipping
  Could not find a version that satisfies the requirement requests (from versions: )
No matching distribution found for requests
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))) - skipping

因此,我在Internet上四处张望,试图找到绕过它的方法,然后尝试.

So I looked all over internet and tried to find to bypass this and tried.

尝试了受信任的主机,但没有成功

Tried trusted host but didn't work out

C:\python3.7>python -m pip install --index-url=http://pypi.org/simple --trusted-host pypi.org --proxy=http://proxypac.novartis.net:2010 requests
Looking in indexes: http://pypi.org/simple
Collecting requests
  Could not find a version that satisfies the requirement requests (from versions: )
No matching distribution found for requests

使用代理和不使用代理均可轻松安装

Easy install with and without proxy

  C:\python3.7>python -m easy_install requests
    Searching for requests
    Reading https://pypi.org/simple/requests/
    Download error on https://pypi.org/simple/requests/: [Errno 11001] getaddrinfo failed -- Some packages may not be found!
    Couldn't find index page for 'requests' (maybe misspelled?)
    Scanning index of all packages (this may take a while)
    Reading https://pypi.org/simple/
    Download error on https://pypi.org/simple/: [Errno 11001] getaddrinfo failed -- Some packages may not be found!
    No local packages or working download links found for requests
    error: Could not find suitable distribution for Requirement.parse('requests')

        C:\python3.7>python -m easy_install requests --proxy=http://proxypac.novartis.net:2010
        Searching for requests
        Reading https://pypi.org/simple/requests/
        Download error on https://pypi.org/simple/requests/: [Errno 11001] getaddrinfo failed -- Some packages may not be found!
        Couldn't find index page for 'requests' (maybe misspelled?)
        Scanning index of all packages (this may take a while)
        Reading https://pypi.org/simple/
        Download error on https://pypi.org/simple/: [Errno 11001] getaddrinfo failed -- Some packages may not be found!
        No local packages or working download links found for requests
        error: Could not find suitable distribution for Requirement.parse('requests')

尝试从git获取

C:\python3.7>python -m pip install git+http://github.com/requests/requests.git
Collecting git+http://github.com/requests/requests.git
  Cloning http://github.com/requests/requests.git to c:\users\gargta2\appdata\local\temp\pip-req-build-dnz33avh
fatal: unable to access 'http://github.com/requests/requests.git/': Could not resolve host: github.com
Command "git clone -q http://github.com/requests/requests.git C:\Users\gargta2\AppData\Local\Temp\pip-req-build-dnz33avh" failed with error code 128 in None

甚至无法使用wheel文件.那太荒谬了.

Not even working with wheel file. That is ridiculous.

C:\python3.7>python -m pip install requests-2.21.0-py2.py3-none-any.whl
Processing c:\python3.7\requests-2.21.0-py2.py3-none-any.whl
Collecting idna<2.9,>=2.5 (from requests==2.21.0)
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x039C3D90>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/idna/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x04567350>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/idna/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x04567D10>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/idna/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x04567FD0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/idna/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x04545F70>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/idna/
  Could not find a version that satisfies the requirement idna<2.9,>=2.5 (from requests==2.21.0) (from versions: )
No matching distribution found for idna<2.9,>=2.5 (from requests==2.21.0)

如@hoefling在注释中建议的,尝试其他命令,但失败:(

As suggested in comments by @hoefling trying another command but it fails :(

C:\python3.7>python -m pip install requests -vvv --index-url=https://pypi.org/simple --trusted-host=pypi.org --trusted-host=files.pythonhosted.org --proxy=http://proxypac.novartis.net:2010?
Config variable 'Py_DEBUG' is unset, Python ABI tag may be incorrect
Config variable 'WITH_PYMALLOC' is unset, Python ABI tag may be incorrect
Created temporary directory: C:\Users\gargta2\AppData\Local\Temp\pip-ephem-wheel-cache-3r4pn3eq
Created temporary directory: C:\Users\gargta2\AppData\Local\Temp\pip-req-tracker-h3p1whde
Created requirements tracker 'C:\\Users\\gargta2\\AppData\\Local\\Temp\\pip-req-tracker-h3p1whde'
Created temporary directory: C:\Users\gargta2\AppData\Local\Temp\pip-install-k9yyg7yl
Collecting requests
  1 location(s) to search for versions of requests:
  * https://pypi.org/simple/requests/
  Getting page https://pypi.org/simple/requests/
  Starting new HTTPS connection (1): pypi.org:443
  Incremented Retry for (url='/simple/requests/'): 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:1056)'))': /simple/requests/
  Starting new HTTPS connection (2): pypi.org:443
  Incremented Retry for (url='/simple/requests/'): Retry(total=3, connect=None, read=None, redirect=None, status=None)
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))': /simple/requests/
  Starting new HTTPS connection (3): pypi.org:443
  Incremented Retry for (url='/simple/requests/'): Retry(total=2, connect=None, read=None, redirect=None, status=None)
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))': /simple/requests/
  Starting new HTTPS connection (4): pypi.org:443
  Incremented Retry for (url='/simple/requests/'): Retry(total=1, connect=None, read=None, redirect=None, status=None)
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))': /simple/requests/
  Starting new HTTPS connection (5): pypi.org:443
  Incremented Retry for (url='/simple/requests/'): Retry(total=0, connect=None, read=None, redirect=None, status=None)
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))': /simple/requests/
  Starting new HTTPS connection (6): pypi.org:443
  Could not fetch URL https://pypi.org/simple/requests/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/requests/ (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))) - skipping
  Could not find a version that satisfies the requirement requests (from versions: )
Cleaning up...
Removed build tracker 'C:\\Users\\gargta2\\AppData\\Local\\Temp\\pip-req-tracker-h3p1whde'
No matching distribution found for requests
Exception information:
Traceback (most recent call last):
  File "C:\python3.7\lib\site-packages\pip\_internal\cli\base_command.py", line 143, in main
    status = self.run(options, args)
  File "C:\python3.7\lib\site-packages\pip\_internal\commands\install.py", line 318, in run
    resolver.resolve(requirement_set)
  File "C:\python3.7\lib\site-packages\pip\_internal\resolve.py", line 102, in resolve
    self._resolve_one(requirement_set, req)
  File "C:\python3.7\lib\site-packages\pip\_internal\resolve.py", line 256, in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "C:\python3.7\lib\site-packages\pip\_internal\resolve.py", line 209, in _get_abstract_dist_for
    self.require_hashes
  File "C:\python3.7\lib\site-packages\pip\_internal\operations\prepare.py", line 218, in prepare_linked_requirement
    req.populate_link(finder, upgrade_allowed, require_hashes)
  File "C:\python3.7\lib\site-packages\pip\_internal\req\req_install.py", line 164, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "C:\python3.7\lib\site-packages\pip\_internal\index.py", line 621, in find_requirement
    'No matching distribution found for %s' % req
pip._internal.exceptions.DistributionNotFound: No matching distribution found for requests
Config variable 'Py_DEBUG' is unset, Python ABI tag may be incorrect
Config variable 'WITH_PYMALLOC' is unset, Python ABI tag may be incorrect
1 location(s) to search for versions of pip:
* https://pypi.org/simple/pip/
Getting page https://pypi.org/simple/pip/
Starting new HTTPS connection (1): pypi.org:443
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))) - skipping

还尝试了其他方法 1.用https更改http 2.我看不到任何pip.ini文件 但似乎没有任何作用.

Also tried other methods 1. changing http with https 2. I don't see any pip.ini file but none seem to be working.

推荐答案

由于您的网络防火墙阻止了您的访问,因此您将需要通过隧道发送pip请求,此链接可以帮助,之后您应该能够通过您的Pip请求建立隧道,可以使用多个VPN提供商允许直通连接,我的建议是NordVPN和DotVPN.

Since your Networks firewall is blocking your access, you will need to tunnel your pip request, this link can help Connect to VPN by Powershell, after that you should be able to tunnel your Pip requests through, there are multiple VPN providers that you can use which allow passthrough connections, My Recommendations are NordVPN and DotVPN.

如果您对通过VPN隧道建立连接有其他疑问,可以在这里查看 https://docs.microsoft.com/zh-CN/powershell/module/vpnclient/add-vpnconnection?view=win10-ps .

If you have additional queries about tunneling your connection through VPN you can have a look here https://docs.microsoft.com/en-us/powershell/module/vpnclient/add-vpnconnection?view=win10-ps.

此外,如果您的网络防火墙阻止了对PyPi的访问,则它们最有可能阻止对VPN的访问,因此,我建议测试一下您尝试通过的VPN是否未被IP阻止. curl的另一种替代方法称为 bitsadmin ,您可以用来验证是否您可以访问vpn,或者只使用老式的ping.

Also if your networks firewall is blocking accessing to PyPi, they are most likely to block access to VPN, so I would recommend testing if the VPN you are trying to tunnel through is not blocked by your IP. There is an alternative to curl known as bitsadmin that you can use to verify if you have access to the vpn, or just use old fashioned ping.

P.S.这两个VPN都有免费层,这就是我的建议.

P.S. Both the VPN's have free tier and that is what I recommend.

如果仍然无法正常工作,请对该错误进行注释.

If it still doesn't work, comment down with the error.

这篇关于无法通过代理使用PIP进行安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 19:44