在CentOS 6下执行python -V发现使用的Python版本是2.6
1 2 |
python -V Python 2.6.6 |
尝试Yum升级:
1 2 3 4 5 6 7 8 9 10 |
yum upgrade python Loaded plugins: fastestmirror Setting up Upgrade Process base | 3.7 kB 00:00 base/primary_db | 4.7 MB 00:00 extras | 3.4 kB 00:00 extras/primary_db | 29 kB 00:00 updates | 3.4 kB 00:00 updates/primary_db | 2.0 MB 00:00 No Packages marked for Update |
找不到升级包,只能通过手动安装
1 2 3 4 5 6 7 8 9 10 11 |
# 准备工作 # 安装相应的包避免因依赖原因导致失败 yum groupinstall "Development tools" -y # 其它可能需要安装的包 yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel # 下载安装 wget --no-check-certificate https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz tar xf Python-2.7.9.tgz cd Python-2.7.9 ./configure --prefix=/usr/local make && make install |
此时执行python -V依然是2.6版本,但使用python2.7 -V会显示刚刚安装的2.7.9版本,也就是说如果使用python2.7来以Python 2.7.9执行命令,显然这样还是有些不便。有多种解决方法,比如将/usr/local/bin/python2.7加入到PATH变量中,也可以用设置别名的方式:
1 2 3 4 5 |
vi ~/.bashrc # 添加内容 alias python=/usr/local/bin/python2.7 # 配置生效 source ~/.bashrc |
此时再执行python -V即会显示2.7.9