問題描述
開了網(wǎng)絡(luò)代理之后,python 的 pip 就無法安裝包了,報如下錯誤:
$ 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
原因分析
想必很多同學(xué)都和我一樣,配置了 pip 源為國內(nèi)的清華源或阿里源,這樣下載包的速度會快,以清華源為例,配置方法如下:
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
然而,配置清華源之后,pip 安裝的時候就是從清華的鏡像倉庫來抓取安裝包,但是清華的網(wǎng)絡(luò)會對一些境外的網(wǎng)絡(luò)代理做屏蔽或過濾,因此導(dǎo)致開了代理之后,pip 就無法安裝包了。
解決方案
臨時方案
臨時方案就很簡單了,直接把代理關(guān)了就行了。但你要安裝很多包的話,就很麻煩,得反復(fù)的開關(guān)代理,推薦下面的永久解決方案。
永久方案
既然 pip 鏡像源(無論還是清華,亦或是阿里)對代理服務(wù)器進行了屏蔽,那么我們訪問鏡像源的時候就不要走代理網(wǎng)絡(luò)了。再系統(tǒng)的代理設(shè)置里面,直接將鏡像源的域名做隔斷處理:文章來源:http://www.zghlxwxcb.cn/news/detail-714829.html
即在代理服務(wù)器設(shè)置里面,請勿對以下條目開頭的地址使用代理服務(wù)器,以清華源為例,就是添加 pypi.tuna.tsinghua.edu.cn
,注意前面的分號 ;
。文章來源地址http://www.zghlxwxcb.cn/news/detail-714829.html
到了這里,關(guān)于【Python】解決 pip 開了網(wǎng)絡(luò)代理之后無法安裝包的問題的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!