更新Python2.7.5到Python2.7.16

Upgrade Python2.7.5 to Python2.7.16

Python has already been installed in Linux by default, but the version is usually not up to date.

Install Python 2.7.16

Download from https://www.python.org/ftp/python/2.7.16/Python-2.7.16.tgz

Specify prefix and use altinstall in case overwriting the default Python.

tar zxvf Python-2.7.16.tgz
cd Python-2.7.16

sudo ./configure --prefix=/usr/local
sudo make
sudo make altinstall
mv /usr/bin/python /usr/bin/python2.7.5
ln -s /usr/local/bin/python2.7 /usr/bin/python

We can find the different version python under usr/bin.

$ python -V
Python 2.7.16
$ python2.7.5 -V
Python 2.7.5
$ python2.7 -V
Python 2.7.16
$ python2 -V
Python 2.7.5

替换旧python的操作,如非真的必要,不建议。

因为替换后发现一些系统命令会出问题,范围似乎也无法预知,有些风险。

No module named yum

Yum does not work after Python upgrade.

$ sudo yum install zlib
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.16 (default, Aug 30 2019, 16:44:16)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]

If you cannot solve this problem yourself, please go to
the yum faq at:
  http://yum.baseurl.org/wiki/Faq
sudo vi /usr/bin/yum

Change #! /usr/bin/python to #! /usr/bin/python2

ImportError: No module named urlgrabber.grabber

Downloading packages:
Traceback (most recent call last):
  File "/usr/libexec/urlgrabber-ext-down", line 22, in <module>
    from urlgrabber.grabber import \
ImportError: No module named urlgrabber.grabber
Traceback (most recent call last):
  File "/usr/libexec/urlgrabber-ext-down", line 22, in <module>
    from urlgrabber.grabber import \
ImportError: No module named urlgrabber.grabber

sudo vi /usr/libexec/urlgrabber-ext-down

Change #! /usr/bin/python to #! /usr/bin/python2

vi Python-2.7.16/Modules/Setup.dist

#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz

Install Python again.

sudo ./configure --prefix=/usr/local
sudo make
sudo make altinstall

ImportError: No module named _ssl

sudo yum install openssl-devel

sudo vi /Modules/Setup
#_socket socketmodule.c timemodule.c
_socket socketmodule.c timemodule.c

Install Python again.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值