1、检查现有python版本
[root@xu ~]# python -V
Python 2.6.6
[root@xu ~]#
2、下载Python3.4.3
下载并上传到tmp目录
[root@xu tmp]# ls
Python-3.4.3.tgz yum.log
[root@xu tmp]#
3、创建Python安装目录
[root@xu tmp]# mkdir /opt/python3.4
4、解压tar文件
[[email protected] tmp]# tar -zxvf Python-3.4.3.tgz
[[email protected] tmp]# cd Python-3.4.3
[[email protected] Python-3.4.3]# pwd
/tmp/Python-3.4.3
5、配置及安装
[[email protected] Python-3.4.3]# ./configure --prefix=/opt/python3.4/
[[email protected] Python-3.4.3]# make
[[email protected] Python-3.4.3]# make install
6、建立软连接,使系统默认python指向新安装的python
[[email protected] tmp]# mv /usr/bin/python /usr/bin/python2.6.6
[[email protected] tmp]# ln -s /opt/python2.7/bin/python2.7 /usr/bin/python
[[email protected] tmp]# python -V
Python 3.4.3
不错,到此升级成功,然后编辑yum默认的python为旧版本python
[[email protected] tmp]# vim /usr/bin/yum
修改第一行,如下
修改前:#!/usr/bin/python
修改后:#!/usr/bin/python2.6.6
保存退出:(vim命令):wq
注意:现在还没有安装easy_install和pip,且安装好后需要配置环境变量
下载setuptools-18.3.2.tar.gz
解压并安装
[[email protected] tmp]# tar -zxvf setuptools-18.3.2.tar.gz
[[email protected] setuptools-18.3.2]# python setup.py install
安装pip
[[email protected] tmp]# easy_install pip
-bash: easy_install: command not found
配置python环境变量
[[email protected] tmp]# vim /etc/profile
在最后面加上
PYTHON_HOME=/opt/python3.4
export PATH=$PYTHON_HOME/bin:$PATH
保存退出
[[email protected] tmp]# source /etc/profile
执行上面命令,是环境变量立即生效
安装pip
[[email protected] tmp]# easy_install pip
Searching for pip
Best match: pip 6.0.8
Adding pip 6.0.8 to easy-install.pth file
Installing pip script to /opt/python3.4/bin
Installing pip3.4 script to /opt/python3.4/bin
Installing pip3 script to /opt/python3.4/bin
Using /opt/python3.4/lib/python3.4/site-packages
Processing dependencies for pip
Finished processing dependencies for pip
到此ok,python升级完成,easy_install和pip命令可以正常使用