相信很多人和我一样饱受pip要查找清华源的苦吧,今天博主也是为大家带来了永久享有清华源的办法,爸妈再也不用担心我网络超时(time out)了(有win和linux两个版本)。
临时调用清华源
在cmd或pycharm的终端中输入如下命令:
pip install 包名[==指定版本] -i https://pypi.tuna.tsinghua.edu.cn/simple
[]中的内容可省,省略表示安装支持的最新版。
pip永久清华源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
其他可用源
https://mirrors.aliyun.com/pypi/simple/ #阿里镜像
https://mirror.baidu.com/pypi/simple/ #百度镜像
https://pypi.mirrors.ustc.edu.cn/simple/ #中科大镜像
http://pypi.douban.com/simple/ #豆瓣镜像
http://mirrors.sohu.com/Python/ #搜狐镜像
https://pypi.hustunique.com/ #华中科大镜像
https://pypi.hustunique.com/ #山东理工大学镜像
永久享有清华源
Windows版
旧版conda需要执行以下命令来生成.condarc文件
conda config --set show_channel_urls yes
新版conda不再支持以上命令,可在C:\Users\用户名下找到该文件,若没有直接创建即可,将文件以记事本打开,并将内容替换为以下内容:
channels:
- defaults
show_channel_urls: true
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
就是有一个缺点:配置后再创建虚拟环境会失败,此时将该文件删掉,用默认源来创建虚拟环境即可。
Linux版
本文将以root用户为例进行阐述,依次执行如下命令
cd root #cd到当前用户的家目录
pwd #确保处于root目录下
ll #查看当前目录中是否有.pip文件夹
mkdir .pip #没有就创建
cd .pip
touch pip.conf #创建配置文件
vim pip.conf #编辑
a
# 在文件中写入如下内容
[global]
index-url=https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=mirrors.tuna.tsinghua.edu.cn
esc #退出编辑
:wq #保存退出
cat pip.conf #查看编辑的内容
从而得到如下结果:
安装一个包看看:
pip install toad
可以使用清华源了