Centos7 安装 Python3 及配置国内源
配置163镜像源
wget -O /etc/yum.repos.d/163.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
rpm方式安装python3
# 安装 python3
yum install -y python3 python3-devel
#################
源码包安装python3
1.官网下载python3源码包
官网:https://www.python.org
2.安装依赖包
yum -y install sqlite-devel tk-devel tcl-devel readline-devel zlib-devel gcc gcc-c++ openssl-devel libffi-devel
3.编译并安装
tar xzf Python3-3.7.2.tgz
cd Python3-3.7.2
./config --prefix=/usr/local/
make && make install
#####################
# 升级 pip 为最新版本
pip3 install pip -U
设置国内镜像源
# 查看当前源地址
pip config list | grep global.index-url
# 设置 pip 为清华源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
Writing to /root/.config/pip/pip.conf
# 确认源地址
pip config list | grep global.index-url
global.index-url='https://pypi.tuna.tsinghua.edu.cn/simple'
pip 临时指定源
# 临时使用 https 源
$ pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U
# 临时使用 http 源,需要加 --trusted-host xxxx,信任不安全源
$ pip install -i http://pypi.doubanio.com/simple pip -U --trusted-host pypi.doubanio.com
参考:https://blog.csdn.net/jlh21/article/details/117474168
备注:自己试验了在~/.pip/pip.conf设置国内镜像站,但是pip和pip3都没有使用国内镜像站下载。正确的应该写入"/root/.config/pip/pip.conf"
[root@docker-105 hello-world]# cat /root/.config/pip/pip.conf
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[root@docker-105 hello-world]#
[root@docker-105 hello-world]# cat ~/.pip/pip.conf
[globle]
index-url = http://mirrors.163.com/pipy/simple/
[install]
trusted-host=mirrors.163.com