我们下载模块的话,如果直接pip安装,一般下载会非常慢,运气不好,直接下载超时,因为默认是使用国外的源进行下载。不知道方法的话,直接弄一天也是有可能的。
如果将下载源修改为国内的,那速度直接起飞。
方法一
一般来说,我们可以直接在安装模块的时候,加上镜像源地址。
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple torch
或者
pip install torch -i https://pypi.tuna.tsinghua.edu.cn/simple
但是这样的话,很麻烦,每次安装还得加个地址,完全没必要。
方法二
我们可以直接使用代码设置 pip 的源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip config set install.trusted-host mirrors.aliyun.com
方法三
对于初学者,这个方法更加一劳永逸,将以下代码保存为图中格式。
[global]
timeout = 6000
index-url = http://pypi.douban.com/simple
trusted-host = pypi.douban.com
保存后将文件复制到系统的个人目录(C:\Users\用户名)就可以解决,顺便放到网盘,就算下次换电脑、换系统了,直接下载放进去就可以了。
文章出处登录后可见!
已经登录?立即刷新