Centos7修改yum源与pip源为清华大学镜像方法

    选择打赏方式

一、CentOS7 yum镜像更换

1.首先备份 CentOS-Base.repo

sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

2.将文件内容清空(文件快捷清空方法可参考本站文章,搜索即可),之后启用 TUNA 软件仓库, 将以下内容写入 /etc/yum.repos.d/CentOS-Base.repo

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

3.清理yum源缓存,并重建缓存

sudo yum clean all
sudo yum makecache

二、CentOS7 pip镜像更换

用pip安装库文件时,默认使用国外的 Mirrors ,因此在国内的下载速度会比较慢,可能只有10KB/s。幸好,国内的一些顶级科研机构已经给我们准备好了各种 Mirrors 。这里推荐清华大学的Mirrors(pypi 镜像每 5 分钟同步一次):

1.临时使用

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple 软件包名

注意,simple 不能少, 是 https 而不是 http。例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pandas,这样就会从清华镜像安装pandas库。

2.设为默认

有两种方法:

(1)升级 pip 到最新的版本 (>=10.0.0) 后进行配置:

pip install pip -U
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

如果您到 pip 默认源的网络连接较差,临时使用清华大学镜像站来升级 pip:

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

(2)修改文件,一劳永逸:

Linux下,修改 ~/.pip/pip.conf( 没有就创建一个文件夹及文件。文件夹要加“.”,表示是隐藏文件夹 )

vi ~/.pip/pip.conf

内容如下:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn

以上操作全部完成后,安装各类东西速度杠杠的!

版权声明:若无特殊注明,本文为《傲世》原创,转载请保留文章出处。
本文链接:https://www.recho.cn/centos7_yum_pypi.html
如您对本文章内容有所疑问、反馈或补充,欢迎通过邮箱:admin@h2fast.cn 联系我们!
正文到此结束

热门推荐