Centos7 安装 Python3 及配置国内源

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

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容