准备编译环境
1 2 3 | 1 2 3 | yum groupinstall 'Development tools'
yum install yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel
readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
|
|
2. 下载安装包
3. 编译
1 2 3 4 5 | 1 2 3 4 5 | tar xf Python-3.5.0.tgz
cd Python-3.5.0
./configure --prefix=/usr/local/python3
make
make install
|
|
4. 设置环境变量
1 | 1 | echo 'export PATH=#PATH:/usr/local/python3/bin' >> ~/.bashrc
|
|
5. 替换python2
1 2 | 1 2 | rm /usr/bin/python
ln -sv /usr/local/bin/python3.5 /usr/bin/python
|
|
(这样做的目的是在系统任意目录下敲入python调用的都是python3.5的命令,而非系统默认的2.6.6。但是这样会导致依赖python2.6的yum不能使用因此还要修改yum配置)
6. 更新yum配置
1 | 1 | ll /usr/bin | grep python
|
|
(这里的/usr/bin目录下面包含以下几个文件的(ll | grep python),其中有个python2.6,只需要指定yum配置的python指向这里)
通过vim修改yum配置,#!/usr/bin/python改为#!/usr/bin/python2.6,保存退出,完成python3的安装
7.运行python