CentOS7 升级python同时解决yum损坏问题

CentOS7中的python版本为python2.7.5,升级到最新版的python时需要注意两个问题

  • 新版的python安装好后要修改python的系统默认指向问题
  • 升级到最新版python后yum报错的问题

下面对新版的安装步骤进行说明。

 一、下载并安装最新版python

  1.下载并解压

# wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
# tar -zxf Python-3.5.2.tgz

  2.安装Python

# cd Python-3.5.2/# ./configure # make# make install

查看是否安装成功

# /usr/local/bin/python3.5Python 3.5.2 (default, Jul 24 2016, 14:46:50) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linuxType "help", "copyright", "credits" or "license" for more information.>>> 

  3.修改python的系统默认指向,修改软链接

  正常情况下,新版本的python安装后系统等其他应用指向的python环境依然是老版本的python,

  如果删除老版本后再装新版本会面临很多难以定位的麻烦,所以通常的做法是:

  老版本依然保留,新版本并行存在。操作方法如下

(1)修改系统默认的python修改为2.7.5版本

# mv /usr/bin/python /usr/bin/python2.7.5

(2)创建软连接使python指向新版本

# ln -s /usr/local/bin/python3.5 /usr/bin/python

(3)检测是否更新成功

[[email protected] ~]# python
Python 3.5.2 (default, Jul 24 2016, 14:46:50)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

 二、yum报错问题解决

  1.终端下输入yum后报错信息如下

[[email protected] ~]# yum
  File "/usr/bin/yum", line 30
    except KeyboardInterrupt, e:
                            ^
SyntaxError: invalid syntax

  2.vim /usr/bin/yum

   修改python头部python为python2.7.5

#!/usr/bin/python2.7.5
import sys
try:
    import yum
except ImportError:
    print >> sys.stderr, """\
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:

  3.再次查看yum是否可用

[[email protected] ~]# yum
Loaded plugins: fastestmirror, langpacks
You need to give some command
Usage: yum [options] COMMAND

List of Commands:

check          Check for problems in the rpmdb
check-update   Check for available package updates
clean          Remove cached data
deplist        List a package‘s dependencies

... ...
时间: 2024-08-25 00:38:17

CentOS7 升级python同时解决yum损坏问题的相关文章

centos7 升级python到3.5.6

centos7 默认安装的python是2.7版本的.因为要安装mysql-utilities,所以想升级python到3.5版本 安装python3.5.6 # 安装python的依赖包 openssl openssl-devel libssl-dev yum install -y openssl openssl-devel gcc libssl-dev mkdir -p /usr/local/webserver/python /download cd /download wget https

[linux]centos7 升级python后出现“No module named yum”错误

公司服务器重新安装系统后,手动升级python2.7.5到2.7.15,安装完python在更新系统python版本的过程中无意删除了系统自带的版本,导致后来在执行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 p

centos7升级Python版本后,yum不能正常使用

执行yum list,提示/usr/bin/yum 报错 我是直接在Python2.7的基础上又另外安装了Python3.6,然后ln -s /usr/local/bin/python3 /usr/bin/python,这样子之后直接执行python就会默认使用Python3.6版本 但是就会出现上面这个问题 恢复方法是使用/usr/bin/python.bak覆盖掉/usr/bin/python,也就是恢复默认使用python2.7版本 怎么才能更好得修改python版本为3.6,暂时还没有想

Centos 6.x 上升级python的解决方法

本文介绍的是在Centos 6.5上将自带的 Python 2.6.6 升级到 2.7.8的方法. 看网上的资料,基本都说因为Centos系统旧版本的python已经被深度依赖,因此卸载原有python或者直接升级到2.7.x都不是特别好的解决方法.只有安装一个新的python比较合适. 1. 下载2.7.8版本的python(2.7.x应该都可以),Gzipped source tar ball(2.7.8)(sig),命令如下: wget https://www.python.org/ftp

升级Python版本后 yum命令不可用

新版本python安装目录 /usr/local/python3 # ./configure --prefix=/usr/local/python3 # make && make install # mv /usr/bin/python /usr/bin/python_old #把旧版本的python移至python_old下 # ln -s /usr/local/python3/bin/python /usr/bin/python #创建新版本链接 # yum -y install gc

解决yum升级的问题“There was a problem importing one of the Python modules”

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 cor

python升级安装后的yum的修复

升级python版本号后,执行yum # yum -y install openssl 提演示样例如以下: 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 veri

centos7   Python安装及yum问题解决

centos7  Python安装及yum问题解决 当前系统centos7.2,系统自带Python版本为2.7.5.现在需要使用Python2.6版本,需要降级. 一,安装Python2.6 1.wget下载python,Python版本为2.6.6.wget http://www.python.org/ftp/python/2.6.6/Python-2.6.6.tgz 2.解压pythontar xzf Python-2.6.6.tgzcd Python-2.6.6 3.编译安装python

Linux升级Python提示Tkinter模块找不到解决

一.安装tkinter 在Linux中python默认是不安装Tkinter模块, [[email protected]193 ~]# python Python 2.6.6 (r266:84292, Feb 22 2013, 00:00:18) [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2 Type "help", "copyright", "credits" or "license