[zyt@localhost python3.6.9]$ sudo yum -y install gcc gcc-c++
[zyt@localhost python3.6.9]$ sudo yum -y install zlib zlib-devel bzip2 bzip2-devel ncurses ncurses-devel readline readline-devel openssl openssl-devel openssl-static xz lzma xz-devel sqlite sqlite-devel gdbm gdbm-devel tk tk-devel libffi libffi-devel
安装python3.6.X
先切换到python3.6.x目录下
配置环境,指定python的安装目录,bin目录、lib目录等都会存放在该路径下
[zyt@localhost python3.6.9]$sudo ./configure --prefix=/usr/local/PythonDir
把源码编译成二进制可执行文件,再进行安装
[zyt@localhost python3.6.9]$ sudo make && sudo make install
sudo vim /etc/profile
将系统默认使用的python2切换为以上安装的python3
切换到/usr/bin 查看 当前python的依赖关系
[zyt@localhost python3.6.9]$ cd /usr/bin
[zyt@localhost bin]$ ls -al python*
先将当前的python备份
[zyt@localhost bin]$ sudo mv python python.bak
创建一个新的软链接
[zyt@localhost bin]$sudo ln -s /usr/local/PythonDir/bin/python3 /usr/bin/python
修改某些系统文件的文件头
[zyt@localhost bin]$ sudo vim /usr/bin/yum
[zyt@localhost bin]$ sudo vim /usr/libexec/urlgrabber-ext-down
修改同上。
至此 ,python3安装完毕
查看当前系统环境的python版本
[zyt@localhost bin]$ python -V
安装pip
[zyt@localhost bin]$ sudo yum -y install epel-release
[zyt@localhost bin]$ sudo yum -y install python-pip
[zyt@localhost bin]$ pip -V
若是python2版本的,则需要新建立软链接
cd /usr/bin
sudo mv pip pip.bak
[zyt@localhost bin]$ ln -s /usr/local/PythonDir/bin/pip3 /usr/bin/pip