zoukankan      html  css  js  c++  java
  • 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.5
    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.
    >>>

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

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

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

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

    1)修改系统默认的python修改为2.7.5版本
    
    # mv /usr/bin/python /usr/bin/python2.7.52)创建软连接使python指向新版本
    
    # ln -s /usr/local/bin/python3.5 /usr/bin/python
    
    (3)检测是否更新成功
    
    [root@localhost ~]# 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后报错信息如下

    [root@localhost ~]# 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是否可用

    [root@localhost ~]# 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
    
    ... ...
  • 相关阅读:
    转载一篇关于kafka零拷贝(zero-copy)通俗易懂的好文
    kafka的一些核心理论知识
    Kafka知识点(Partitions and Segments)
    kafka: Producer配置和Consumer配置
    kafka: Java实现简单的Producer和Consumer
    SAP抛xml资料到kafka(本机模拟)
    解决方法: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation
    kafka log保存在本机的位置 kafka数据保存的位置
    Kafka: 下载安装和启动
    tomcat错误提示:指定的服务未安装。Unable to open the service 'tomcat9'的原因和解决方法
  • 原文地址:https://www.cnblogs.com/tdcqma/p/5700832.html
Copyright © 2011-2022 走看看