在Linux 6.x 下默认的Python 版本是2.6.6. 根据上篇博客的说明,Python 2.6 将不再被核心团队支持。 所以将Python 升级到最新的2.7.14.
Python 更改 PyPI 源
http://www.cndba.cn/dave/article/2261
具体的升级步骤如下:
1) 从官网下载源码包
https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz
2) 安装新版Python
在编译前先在/usr/local建一个文件夹python2.7:
[dave@www.cndba.cn bin]# mkdir /usr/local/python2.7
[dave@www.cndba.cn ~]# tar xzvf Python-2.7.14.tgz
[dave@www.cndba.cn ~]# cd Python-2.7.14
[dave@www.cndba.cn Python-2.7.14]# ls
aclocal.m4    configure     Doc      install-sh  Mac              Modules  PC             Python  setup.py
config.guess  configure.ac  Grammar  Lib         Makefile.pre.in  Objects  PCbuild        README  Tools
config.sub    Demo          Include  LICENSE     Misc             Parser   pyconfig.h.in  RISCOS
[dave@www.cndba.cn Python-2.7.14]#
[dave@www.cndba.cn Python-2.7.14]# ./configure
[dave@www.cndba.cn Python-2.7.14]# make && make install
 
3) 善后操作
将原来/usr/bin/python链接改为别的名字
[dave@www.cndba.cn Python-2.7.14]# mv /usr/bin/python /usr/bin/python2.6.6
 
建立新版本python的链接
[dave@www.cndba.cn Python-2.7.14]# ln -s /usr/local/python2.7/bin/python /usr/bin/python
[dave@www.cndba.cn Python-2.7.14]# python -V
Python 2.7.14
[dave@www.cndba.cn Python-2.7.14]#
 
4)更改YUM的Python版本
另外要注意,YUM只支持默认的python2.6.6. 升级之后,yum 会异常。
[dave@www.cndba.cn Python-2.7.14]# yum list all
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
   No module named yum
Please install a package which provides this module, or
verify that the module is installed correctly.
It's possible that the above module doesn't match the
current version of Python, which is:
2.7.14 (default, Oct  1 2017, 10:20:19) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)]
If you cannot solve this problem yourself, please go to 
the yum faq at:
  http://yum.baseurl.org/wiki/Faq
 
需要修改yum文件,改成默认的python即可。 修改第一行:
[dave@www.cndba.cn Python-2.7.14]# cat /usr/bin/yum
#!/usr/bin/python2.6.6
						
							版权声明:本文为博主原创文章,未经博主允许不得转载。
- 上一篇:Python 更改 PyPI 源
 - 下一篇:Python 搭建本地PIP源
 

					
					
				
			

