CentOS安装python3
- 下载python源码至服务器 https://registry.npmmirror.com/binary.html?path=python/ (根据自己的需要去下载对应的版本)
wget http://npm.taobao.org/mirrors/python/3.7.5/Python-3.7.5.tgz
- 下载py3编译依赖相关库
yum install -y gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
- 解压源码编译安装
- 解压源码
tar -zxvf Python-3.7.5.tgz
- 指定安装目录 (这里指定编译文件存放位置为
/opt/python37
)
cd Python-3.7.5
./configure --prefix=/opt/python37
- 编译、安装
make && make install
- 创建软连接
ln -s /opt/python37/bin/python3 /usr/bin/python3
ln -s /opt/python37/bin/pip3 /usr/bin/pip3
- 验证
[root@it bin]# python3 -V
Python 3.7.5
[root@it bin]#
[root@it bin]#
[root@it bin]# python3
Python 3.7.5 (default, Mar 31 2021, 09:48:01)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
补充当前系统信息
[root@it ~]#
[root@it ~]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
[root@it ~]# uname -a
Linux it.novalocal 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[root@it ~]#
[root@it ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@it ~]#