Python- 解決PIP下載安裝時因為網絡速度慢而導致失敗的方法


讓PIP源使用國內鏡像,提升下載速度和安裝成功率。

國外的源下載速度太慢,而且經常出現下載后安裝出錯問題。把PIP安裝源替換成國內鏡像,可以大幅提升下載速度,還可以提高安裝成功率。

國內源:

新版ubuntu要求使用https源,要注意。

清華:https://pypi.tuna.tsinghua.edu.cn/simple

阿里雲:http://mirrors.aliyun.com/pypi/simple/

中國科技大學 https://pypi.mirrors.ustc.edu.cn/simple/

華中理工大學:http://pypi.hustunique.com/

山東理工大學:http://pypi.sdutlinux.org/ 

豆瓣:http://pypi.douban.com/simple/

臨時使用:

可以在使用pip的時候加參數-i https://pypi.tuna.tsinghua.edu.cn/simple

例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyspider,這樣就會從清華這邊的鏡像去安裝pyspider庫。

永久修改,一勞永逸:

Linux下,修改 ~/.pip/pip.conf (沒有就創建一個文件夾及文件。文件夾要加“.”,表示是隱藏文件夾)

內容如下:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=mirrors.aliyun.com

windows下,在user目錄中創建一個pip目錄,如:C:\Users\xx\pip,新建文件pip.ini。內容同上。

 

 

pip 安裝模塊失敗問題

1.先在命令行中輸入安裝 wheel
pip3 install wheel

問題1:

ERROR: Could not find a version that satisfies the requirement xlwt (from vers

ions: none)

ERROR: No matching distribution found for xlwt

原因:網絡問題或者是pip版本需要更新

pip升級:python -m pip install --upgrade pip

網絡問題更換金鏡像源:pip install https://pypi.tuna.tsinghua.edu.cn/simple 模塊名

按照上述操作后,出現了問題2

報錯: ERROR: Cannot unpack file c:\users\admini~1\appdata\local\temp\pip-unpack-uwt0

as\simple (downloaded from c:\users\admini~1\appdata\local\temp\pip-req-build-7m

zbzm, content-type: text/html; charset=utf-8); cannot detect archive format

ERROR: Cannot determine archive format of c:\users\admini~1\appdata\local\temp\p

ip-req-build-7mzbzm

使用以下命令安裝成功:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn 模塊名

原始解決方案網站:https://blog.csdn.net/cn_1937/article/details/81449484


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM