最近需要在linux下使用python,故需要升级一下python版本,上网查询了一下相关资料,更新了一下linux下面的python环境,记录如下:

linux下面升级 Python版本并修改yum属性信息

首先linux下查询python版本

[root@test30 chengshaoling]# python -V

Python 2.7.5

1.最新版本python下载安装

下载新版本的python

python主站相关地址:

https://www.python.org/downloads/source/

https://www.python.org/downloads/release/python-2712/

https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tgz

[root@test30 makePython]# wget   https://www.python.org/downloads/release/python-373/Python-3.7.3.tgz   #下载的不完整,又手动网页下载,上传到Linux系统的

解压缩 以及编译

[root@test30 makePython]# tar -xvf Python-2.7.12.tgz

[root@test30 makePython]# cd Python-2.7.12

[root@test30 Python-2.7.12]# ./configure --prefix=/usr/local/python27    #我运行了   ./configure  后又运行了./configure --prefix=/usr/local/python37

[root@test30 Python-2.7.12]# make

[root@test30 Python-2.7.12]# make install

再次查看python版本,系统展现版本未更新

[root@test30 Python-2.7.12]# python -V

Python 2.7.5

2. python多版本共存解决

下面来解决这个问题

把原来的python重命名成python_old,注意不要删除

[root@test30 Python-2.7.12]# mv /usr/bin/python /usr/bin/python_old

[root@test30 Python-2.7.12]# ln -s /usr/local/python37/bin/python3 /usr/bin/python

再查看一下版本

[root@test30 Python-2.7.12]#python -V

Python 3.7.3

成功更新python版本

3.解决yum的python版本问题

还有最后一个问题要解决,因为yum是使用的python2.7.5的版本,所以 还需要修改一下yum的python版本(利用前面重命名的python_old文件夹的内容)

[root@test30 Python-2.7.12]# 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.12 (default, Nov 29 2016, 11:07:49)

[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]

If you cannot solve this problem yourself, please go to

the yum faq at:

http://yum.baseurl.org/wiki/Faq

修改yum文件中配置的python程序位置:

[root@test30 Python-2.7.12]# cd /usr/bin/

[root@test30 bin]# vi yum

#!/usr/bin/python_old    #修改此处为原始python程序的位置  #后边不能写注释,会出问题  不知道为啥

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:

%s

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:

%s

If you cannot solve this problem yourself, please go to

the yum faq at:

http://yum.baseurl.org/wiki/Faq

""" % (sys.exc_value, sys.version)

sys.exit(1)

sys.path.insert(0, '/usr/share/yum-cli')

try:

import yummain

yummain.user_main(sys.argv[1:], exit_code=True)

except KeyboardInterrupt, e:

print >> sys.stderr, "\n\nExiting on user cancel."

sys.exit(1)

~

~

~

~

~

~

~

~

~

~

~

"yum" 32L, 805C

验证 yum 是否重新可以使用

[root@test30 bin]# yum

已加载插件:fastestmirror

你需要给出命令

Usage: yum [options] COMMAND

List of Commands:

check          Check for problems in the rpmdb

check-update   检查是否有软件包更新

clean          删除缓存的数据

deplist        列出软件包的依赖关系

distribution-synchronization Synchronize installed packages to the latest available versions

downgrade      downgrade a package

erase          从系统中移除一个或多个软件包

groupinfo      显示组的详细信息

groupinstall   向系统中安装一组软件包

grouplist      列出可安装的组

groupremove    从系统中移除一组软件包

help           显示用法信息

history        Display, or use, the transaction history

info           显示关于软件包或组的详细信息

install        向系统中安装一个或多个软件包

list           列出一个或一组软件包

load-transaction load a saved transaction from filename

makecache      创建元数据缓存

provides       查找提供指定内容的软件包

reinstall      覆盖安装一个包

repolist       显示已配置的仓库

resolvedep     判断哪个包提供了指定的依赖

search         在软件包详细信息中搜索指定字符串

shell          运行交互式的 yum 外壳

update         更新系统中的一个或多个软件包

upgrade        更新软件包同时考虑软件包取代关系

version        Display a version for the machine and/or available repos.

Options:

-h, --help            show this help message and exit

-t, --tolerant        容忍错误

-C, --cacheonly       run entirely from system cache, don't update cache

-c [config file], --config=[config file]

配置文件路径

-R [minutes], --randomwait=[minutes]

命令最长等待时间

-d [debug level], --debuglevel=[debug level]

调试输出级别

--showduplicates      在 list/search 命令下,显示仓库里重复的条目。

-e [error level], --errorlevel=[error level]

错误输出级别

--rpmverbosity=[debug level name]

debugging output level for rpm

-q, --quiet           安静的操作

-v, --verbose         verbose operation

-y, --assumeyes       回答所有的问题为是

--assumeno            answer no for all questions

--version             显示 Yum 版本信息并退出

--installroot=[path]  设置目标根目录

--enablerepo=[repo]   启用一个或多个仓库(支持通配符)

--disablerepo=[repo]  禁用一个或多个仓库(支持通配符)

-x [package], --exclude=[package]

用全名或通配符排除软件包

--disableexcludes=[repo]

禁止从主配置,从仓库或者从任何位置排除

--obsoletes           升级时考虑软件包取代关系

--noplugins           禁用 Yum 插件

--nogpgcheck          禁用 gpg 签名检测

--disableplugin=[plugin]

禁用指定名称的插件

--enableplugin=[plugin]

enable plugins by name

--skip-broken         跳过有依赖问题的软件包

--color=COLOR         配置是否使用颜色

--releasever=RELEASEVER

set value of $releasever in yum config and repo files

--downloadonly        don't update, just download

--downloaddir=DLDIR   specifies an alternate directory to store packages

--setopt=SETOPTS      set arbitrary config and repo options

插件选项:

至此,python升级完成

参考:http://blog.sina.com.cn/s/blog_53f023270102vdvo.html

参考:https://blog.csdn.net/jiangshan35/article/details/69568271

参考:https://www.cnblogs.com/eleganthua/p/9406968.html

总结:python 升级;默认调用改为升级后的Python;但是,yum不能配套使用升级后的Python,yum 改为默认路径为老的Python包路径;

linux下面升级 Python版本并修改yum属性信息的更多相关文章

  1. linux服务器升级python版本(python2与python3共存)

    linux服务器升级python版本 ######################################## 第一步先安装sqlite-devel,因为python2也有这个,python3 ...

  2. Linux下升级python版本

    转载自:http://lovebeyond.iteye.com/blog/1770476 CentOS下的Python版本一般都比较低,很多应用都需要升级python来完成.我装的centOS的默认的 ...

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

    python升级方法,使用源码编译安装即可,prefix=/usr/local/bin/python3 执行yum list,提示/usr/bin/yum 报错 我是直接在Python2.7的基础上又 ...

  4. Ubutnu linux 下升级python版本,以2.x升级到3.x为例

    Linux操作系统一般 都会自带python,但是python版本会比主流低,故升级python, 主要思路:自带的python的链接link文件是在/usr/bin 下,采用sudo apt-get ...

  5. linux多个python版本下导致yum报错

    问题: $ yum File "/usr/bin/yum", line 30 except KeyboardInterrupt, e: ^ SyntaxError: invalid ...

  6. Linux系统下升级Python版本步骤(suse系统)

    Linux系统下升级Python版本步骤(suse系统) http://blog.csdn.net/lifengling1234/article/details/53536493

  7. CentOS 5升级Python版本(2.4>2.7)

    安装SALT时,需要这样作,公司有一批REDHAT5的,弄起来... 然后却是: Missing Dependency: python(abi) = 2.6 is needed by package ...

  8. CentOS 6下升级Python版本

    CentOS6.8默认的python版本是2.6,而现在好多python组件开始只支持2.7以上的版本,比如说我今天遇到的pip install pysqlite,升级python版本是一个痛苦但又常 ...

  9. CentOs 6.x 升级 Python 版本【转】

    在CentOS 6.X 上面安装 Python 2.7.X CentOS 6.X 自带的python版本是 2.6 , 由于工作需要,很多时候需要2.7版本.所以需要进行版本升级.由于一些系统工具和服 ...

随机推荐

  1. 并发编程从零开始(八)-ConcurrentHashMap

    并发编程从零开始(八)-ConcurrentHashMap 5.5 ConcurrentHashMap HashMap通常的实现方式是"数组+链表",这种方式被称为"拉链 ...

  2. Spring Cloud Gateway Route Predicate Factory 的使用

    Spring Cloud Gateway的使用 一.需求 二.基本组成 1.简介 2.核型概念 1.Route 路由 2.Predicate 谓语.断言 3.Filter 过滤器 3.工作原理 三.网 ...

  3. js基础学习之"=="与"==="的区别

    var a = 1; var b = 1; var c = "1"; 1. "==" 可理解为相等运算符.相等运算符比较时,会自己进行类型转换,等于什么类型就会 ...

  4. ASP.NET WEBAPI 跨域请求 405错误

    浏览器报错 本来没有报这个错,当我在ajax中添加了请求头信息时报错 405的报错大概就是后端程序没有允许此次请求,要解决这个问题,就是在后端程序中允许请求通过.具体操作就是修改web.config配 ...

  5. 跳台阶 牛客网 剑指Offer

    跳台阶 牛客网 剑指Offer 题目描述 一只青蛙一次可以跳上1级台阶,也可以跳上2级.求该青蛙跳上一个n级的台阶总共有多少种跳法(先后次序不同算不同的结果). class Solution: #ru ...

  6. httprunner3源码解读(1)简单介绍源码模块内容

    前言 最近想着搭建一个API测试平台,基础的注册登录功能已经完成,就差测试框架的选型,最后还是选择了httprunner,github上已经有很多开源的httprunner测试平台,但是看了下都是基于 ...

  7. PTA甲级1094 The Largest Generation (25分)

    PTA甲级1094 The Largest Generation (25分) A family hierarchy is usually presented by a pedigree tree wh ...

  8. RDD的缓存

    RDD的缓存/持久化 缓存解决的问题 缓存解决什么问题?-解决的是热点数据频繁访问的效率问题 在Spark开发中某些RDD的计算或转换可能会比较耗费时间, 如果这些RDD后续还会频繁的被使用到,那么可 ...

  9. ES6—数值(Number,Math对象)(复习+学习)

    ES6-数值(Number,Math对象)(复习+学习) 每天一学,今天要学习ES6的关于数的扩展以及复习,然后通过看书,查阅资料,以及webAPI来搞清楚遇到的,没见过的对象方法等等,下面为本次学习 ...

  10. 菜鸡的Java笔记 - java 双向一对多映射

    双向一对多映射    two-way    开发要求:        根据数据表的结构进行简单java类的转换:        要求实现如下的输出信息:            可以根据课程取得全部参与 ...