您的位置:首页 > 运维架构 > Linux

CentOS 6.5 升级python到版本2.7.14

2018-01-19 17:15 441 查看
环境:CentOS 6.5 64bit
CentOS 6.5 64bit 默认python版本:
[dup@localhost Downloads]$ python --version
Python 2.6.6


源码安装python 2.7.14步骤:1.下载python 2.7.14源码
[dup@localhost Downloads]$ wget https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz2.解压
[dup@localhost Downloads]$ tar zxvf Python-2.7.14.tgz
3.更改工作目录
[dup@localhost Downloads]$ cd Python-2.7.14
4.编译安装
[dup@localhost Python-2.7.14]$ ./configure
[dup@localhost Python-2.7.14]$ make
[dup@localhost Python-2.7.14]$ sudo make install5.查看安装python版本信息[dup@localhost Python-2.7.14]$ /usr/local/bin/python2.7 --version
Python 2.7.14[dup@localhost Python-2.7.14]$ ll /usr/local/bin/
total 6668
-rwxrwxr-x 1 root root 101 Jan 19 00:53 2to3
-rwxrwxr-x 1 root root 99 Jan 19 00:53 idle
-rwxr-xr-x 1 root root 1461 Jan 17 18:59 libmcrypt-config
-rwxr-xr-x 1 root root 232465 Jan 17 19:04 mcrypt
lrwxrwxrwx 1 root root 6 Jan 17 19:04 mdecrypt -> mcrypt
-rwxr-xr-x 1 root root 2363 Jan 11 23:23 pcre-config
-rwxr-xr-x 1 root root 90015 Jan 11 23:23 pcregrep
-rwxr-xr-x 1 root root 181880 Jan 11 23:23 pcretest
-rwxrwxr-x 1 root root 84 Jan 19 00:53 pydoc
lrwxrwxrwx 1 root root 7 Jan 19 00:56 python -> python2
lrwxrwxrwx 1 root root 9 Jan 19 00:56 python2 -> python2.7
-rwxr-xr-x 1 root root 6273987 Jan 19 00:55 python2.7
-rwxr-xr-x 1 root root 1687 Jan 19 00:56 python2.7-config
lrwxrwxrwx 1 root root 16 Jan 19 00:56 python2-config -> python2.7-config
lrwxrwxrwx 1 root root 14 Jan 19 00:56 python-config -> python2-config
-rwxrwxr-x 1 root root 18547 Jan 19 00:53 smtpd.py
6.建立软连接,使系统默认的python指向python2.7,依次执行:
[dup@localhost Python-2.7.14]$ mv /usr/bin/python /usr/bin/python2.6.6
[dup@localhost Python-2.7.14]$ sudo ln -s /usr/local/bin/python2.7 /usr/bin/python
7.再次检查python版本
[dup@localhost Python-2.7.14]$ python --version
Python 2.7.14
目前已经是新版本。8.解决系统 python 软链接指向 python2.7 版本后,因为yum是不兼容 python 2.7的,所以yum不能正常工作,需要指定 yum 的python版本。
[dup@localhost Python-2.7.14]$ yum
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, Jan 19 2018, 00:52:34)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)]

If you cannot solve this problem yourself, please go to
the yum faq at: http://yum.baseurl.org/wiki/Faq
#vim /usr/bin/yum
将文件头部的
#!/usr/bin/python
改成
#!/usr/bin/python2.6.6
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: