[Python] Solve the problem that the package cannot be installed after pip opens the network proxy

Problem Description

After opening the network proxy, python's pip cannot install the package, and the following error is reported:

$ pip install netsm
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1123)'))': /simple/netsm/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1123)'))': /simple/netsm/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1123)'))': /simple/netsm/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1123)'))': /simple/netsm/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1123)'))': /simple/netsm/
Could not fetch URL https://pypi.tuna.tsinghua.edu.cn/simple/netsm/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.tuna.tsinghua.edu.cn', port=443): Max retries exceeded with url: /simple/netsm/ (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1123)'))) - skipping
ERROR: Could not find a version that satisfies the requirement netsm (from versions: none)
ERROR: No matching distribution found for netsm

Cause Analysis

Presumably many students are like me, configuring the pip source as the domestic Tsinghua source or Ali source, so that the download speed of the package will be faster. Taking Tsinghua source as an example, the configuration method is as follows:

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

However, after configuring the Tsinghua source, pip will grab the installation package from Tsinghua’s mirror warehouse when installing, but Tsinghua’s network will block or filter some overseas network proxies, so after the proxy is enabled, pip cannot be installed packaged.

solution

temporary plan

The temporary solution is very simple, just turn off the agent. But if you want to install many packages, it will be very troublesome. You have to switch the proxy repeatedly. The following permanent solution is recommended.

permanent program

Since the pip mirror source (whether it is Tsinghua University or Ali) has shielded the proxy server, then we should not use the proxy network when accessing the mirror source. In the proxy settings of the system, directly isolate the domain name of the mirror source:

insert image description here
That is, in the proxy server settings, do not use the proxy server for the addresses beginning with the following entries. Take Tsinghuayuan as an example, just add pypi.tuna.tsinghua.edu.cn, pay attention to the semicolon in front ;.

Guess you like

Origin blog.csdn.net/qq_42951560/article/details/132339370