安装的CentOS系统自带python2.7版本的,在这里只需再下载安装python3即可。
1.安装依赖环境
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
2.下载python3
python3.6.5下载链接
3.安装python3
包安装存放在/usr/local/python3
创建目录安装路径:mkdir /usr/local/python3
进入下载好的python3路径下,进行解压tar -xzvf Python3.6.5.tgz
进入解压后的目录cd Python3.6.5,./configure --prefix=/usr/lcoal/python3
编译安装 ,先make,然后make install
4.安装好python3,建立python3软连接
ln -s /usr/lcoal/python/bin/python3 /usr/bin/python3
5.配置环境变量
进入~/.bash_profile
#vim ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs PATH=$PATH:$HOME/bin:/usr/local/python3/bin
export PATH
保存,退出,source ~/.bash_porfile
6. 检查python3及pip3是否正常可用:
[root@master ~]# python3 -V
Python 3.6.5
[root@master ~]# python2 -V
Python 2.7.5