博客 / 詳情

返回

pip安裝更換鏡像

原文鏈接

使用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/pyp...

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

清華大學:https://pypi.tuna.tsinghua.ed...

中國科學技術大學:http://pypi.mirrors.ustc.edu....

華中理工大學: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 <module> 改為 pip install --user <module>

pip install --user -i https://pypi.tuna.tsinghua.edu.cn/simple torch

 
 

學習更多編程知識,請關注我的公眾號:

代碼的路

user avatar
0 位用戶收藏了這個故事!

發佈 評論

Some HTML is okay.