日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

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

發布時間:2024/4/15 linux 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux下面升级 Python版本并修改yum属性信息 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

最近需要在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包路徑;

轉載于:https://www.cnblogs.com/Formulate0303/p/11121562.html

總結

以上是生活随笔為你收集整理的linux下面升级 Python版本并修改yum属性信息的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。