Conda,pip永久享有清华源保姆级教程

相信很多人和我一样饱受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

在这里插入图片描述

可以使用清华源了

  • 11
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值