0.引言
这篇博文记录毛毛张在配置深度学习环境中使用镜像源的教程,引用了几篇文章,均放在文章最后,力求把问题说清楚讲明白。
1.镜像源
由于众所周知的原因,如果没有vpn
我们无法访问国外的网站。但是由于深度学习环境配置过程中的许多包都是国外提供的,因此网站的服务器也在国外,导致我们无法直接访问或者下载很慢。而镜像源就是把国外官方的源作了一个镜像,使得你可以在该镜像源网站上这下载软件。
国内常用镜像源
- 清华大学 (推荐):https://pypi.tuna.tsinghua.edu.cn/simple/
- 阿里云:http://mirrors.aliyun.com/pypi/simple/
- 中国科技大学:https://pypi.mirrors.ustc.edu.cn/simple/
- 中国科学技术大学:http://pypi.mirrors.ustc.edu.cn/simple/
- 豆瓣:http://pypi.douban.com/simple/
2.pip安装命令使用国内镜像源
1.临时使用
语法:pip install 包名 -i 镜像源
示例:
pip install scrapy -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
2.永久修改
Windows系统
-
在
User
目录中创建一个pip
目录,如:C:\Users\mmz\pip
; -
在
pip目录
下新建文件pip.txt
并该后缀为ini
,即:pip.ini
; -
在
pip.ini
中添加如下内容:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn
添加
trusted-host
参数是为了避免麻烦,否则使用的时候可能会提示不受信任
Liunx系统
命令行操作:
# Linux中先升级pip为最新版本,再改源
$ pip install pip -U
$ pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
手动操作
Linux文件管理器中操作:
-
进入根目录,新建目录
.pip/
; -
并在该目录下新建文件
pip.conf
; -
粘贴如下内容到
pip.conf
文件中,保存并退出。[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple [install] trusted-host = https://pypi.tuna.tsinghua.edu.cn
Linux命令行中操作(可以帮助大家熟悉命令行操作):
-
首先需要切换到根目录下,切换到该目录下需要
root
权限,因此使用命令sudo su
然后输入密码获得权限就会自动切换到root
权限; -
并用
vim
编辑器编辑~/.pip/pip.conf
文件(如果没有则新建一个);(base) mmz@mmz:~$ sudo su [sudo] password for flyvideo: root@mmz:/home/mmz# vim ~/.pip/pip.conf
-
并在用
vim
编辑器打开的pip.conf
中输入如下内容:[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple [install] trusted-host = https://pypi.tuna.tsinghua.edu.cn
添加
trusted-host
参数是为了避免麻烦,否则使用的时候可能会提示不受信任
参考文献
- https://zhuanlan.zhihu.com/p/435841219
- https://blog.csdn.net/qq_43382635/article/details/108780369
- https://blog.csdn.net/xuezhangjun0121/article/details/81664260
- https://blog.csdn.net/Hunter_Murphy/article/details/106098052
hangjun0121/article/details/81664260 - https://blog.csdn.net/Hunter_Murphy/article/details/106098052
- https://www.cnblogs.com/librarookie/p/14930238.html