使用pip來安裝python包有時候安裝起來會非常慢,因此需要換成國內的源來加速下載:
1 單次修改源
以Torch為例,常規下載方式為:
pip install torch
修改為阿里源:
pip install -i https://mirrors.aliyun.com/pypi/simple torch
2 修改默認源
如果不想在每一次下載都指定源,可以直接修改默認源。
2.1 Linux
linux下運行命令:
vi ~/.pip/pip.conf
然后寫入如下內容并保存(以阿里源為例):
[global]
trusted-host = mirrors.aliyun.com
index-url = https://mirrors.aliyun.com/pypi/simple
2.2 Windows
windows下找到pip.ini
文件,默認路徑為:C:\\Users\\xxx\\AppData\\Roaming\\pip\\pip.ini
。
然后寫入如下內容并保存(以阿里源為例):
[global]
trusted-host = mirrors.aliyun.com
index-url = https://mirrors.aliyun.com/pypi/simple
3 常用的國內源
阿里云:http://mirrors.aliyun.com/pypi/simple/
豆瓣 :http://pypi.doubanio.com/simple/
清華大學:https://pypi.tuna.tsinghua.edu.cn/simple/
中國科學技術大學:http://pypi.mirrors.ustc.edu.cn/simple/
華中理工大學:http://pypi.hustunique.com/
山東理工大學:http://pypi.sdutlinux.org/
4 常見報錯
4.1 若無法連接
WARNING: The repository located at pypi.doubanio.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host pypi.doubanio.com'.
ERROR: Could not find a version that satisfies the requirement opencv-python (from versions: none)
ERROR: No matching distribution found for opencv-python
可以將源中的http改為https
4.2 需要 user
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/anaconda3/lib/python3.7/site-packages/llvmlite-0.28.0.dist-info'
Consider using the
--user
option or check the permissions.
需要加上--user:pip install 改為 pip install --user
pip install --user -i https://pypi.tuna.tsinghua.edu.cn/simple torch
審核編輯:湯梓紅
-
Linux
+關注
關注
87文章
11345瀏覽量
210392 -
Shell
+關注
關注
1文章
366瀏覽量
23445 -
鏡像
+關注
關注
0文章
170瀏覽量
10802
發布評論請先 登錄
相關推薦
【Banana Pi M1+試用體驗】bananapi的pip安裝步驟及使用詳解
Linux的pip安裝步驟
pip 的超全使用指南
TensorFlow安裝手冊之如何利用pip安裝 TensorFlow
教程分享:Pip安裝如何使用國內鏡像源
使用pip安裝、更新和卸載Python的第三方庫
pip安裝更換鏡像
pip安裝后仍有ImportError No module named XX問題解決
pip安裝報錯:Command python setup.py egg_info failed with error code 1
![<b class='flag-5'>pip</b><b class='flag-5'>安裝</b>報錯:Command python setup.py egg_info failed with error code 1](https://file.elecfans.com/web2/M00/8A/E5/pYYBAGO_uieAYU-QAADIw1NhCig646.png)
評論