惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
博客园_首页
W
WeLiveSecurity
S
Secure Thoughts
S
Security @ Cisco Blogs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Hugging Face - Blog
Hugging Face - Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
H
Hacker News: Front Page
Project Zero
Project Zero
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
U
Unit 42
N
News and Events Feed by Topic
N
News and Events Feed by Topic
Hacker News - Newest:
Hacker News - Newest: "LLM"
Forbes - Security
Forbes - Security
T
Tor Project blog
I
Intezer
B
Blog
F
Full Disclosure
Security Archives - TechRepublic
Security Archives - TechRepublic
F
Fortinet All Blogs
Schneier on Security
Schneier on Security
T
Threat Research - Cisco Blogs
AI
AI
Google DeepMind News
Google DeepMind News
L
LINUX DO - 最新话题
Cloudbric
Cloudbric
L
Lohrmann on Cybersecurity
WordPress大学
WordPress大学
博客园 - 聂微东
雷峰网
雷峰网
P
Privacy International News Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
PCI Perspectives
PCI Perspectives
Y
Y Combinator Blog
Spread Privacy
Spread Privacy
Simon Willison's Weblog
Simon Willison's Weblog
罗磊的独立博客
Vercel News
Vercel News
A
Arctic Wolf
The Register - Security
The Register - Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Azure Blog
Microsoft Azure Blog
H
Heimdal Security Blog
Know Your Adversary
Know Your Adversary
P
Proofpoint News Feed
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed

博客园 - 疯吻IT

timestamp for this request was 1000ms ahead of the server's time GitHub无法访问、443 Operation timed out的解决办法 - 疯吻IT Ccxt: ModuleNotFoundError:没有名为“ ccxt”的模块 机器翻译数据集 Python3 找不到库 UnicodeDecodeError: 'ascii' codec can't decode byte 0xa0 in position 0: ordinal not in range(128) 数据集 rnn_model.fit Incompatible shapes Mysql 密码过期 帝国cms打开慢 如何快速获得权重站 HTTP 404 Not Found Error with .woff or .woff2 Font Files php报错 syntax error, unexpected T_VARIABLE 修改帝国cms栏目后,如何更新 用python 发 帝国cms 文章 帝国cms更新报错解决办法 帝国cms 不能正常显示最新文章 帝国CMS Table '***.phome_ecms_news_data_' doesn't exist 多版本python及多版本pip使用 python 去重
CENTOS手动安装修复python ,YUM CENTOS手动安装修复YUM
疯吻IT · 2019-03-18 · via 博客园 - 疯吻IT

一、问题场景

centos 上的 python 版本默认比较低,很多同学都会手动升级 python 的版本到 3.x。

因为 yum 的代码是依赖 python2.x 的,如果直接删除老版本 python ,会导致 yum 不可用。

# 报错核心语句 No module named yum

这个情况必须手动修复,很多同学因为修复失败而重装了系统,这样成本会很高。

这里以 centos7.5 x64 为例子,进行修复演示。

二、手动修复

2.1 下载 rpm 包

centos 官方下载网站是 http://mirror.centos.org/centos/。选择国内镜像网站会快一些。这里使用的是 mirrors.ustc.edu.cn。

首页就有各个方向的目录链接。

进到 7.5 对应的目录 http://mirrors.ustc.edu.cn/centos/7.5.1804/, 发现这里是空的。不过这没有关系,同一个大版本号下, rpm 包是兼容的。所以可以使用 7.6 目录下的包。

http://mirrors.ustc.edu.cn/centos/7.6.1810/os/x86_64/Packages/ ,这里就是我们所需的 python 和 yum 包 所在地。

下载如下包

# python 部分 python-backports-1.0-8.el7.x86_64.rpm python-pycurl-7.19.0-19.el7.x86_64.rpm python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch.rpm python-ipaddress-1.0.16-2.el7.noarch.rpm python-setuptools-0.9.8-7.el7.noarch.rpm python-urlgrabber-3.10-9.el7.noarch.rpm python-2.7.5-76.el7.x86_64.rpm python-iniparse-0.4-9.el7.noarch.rpm python-libs-2.7.5-76.el7.x86_64.rpm python-devel-2.7.5-76.el7.x86_64.rpm rpm-4.11.3-35.el7.x86_64.rpm rpm-python-4.11.3-35.el7.x86_64.rpm # yum 部分 yum-3.4.3-161.el7.centos.noarch.rpm yum-metadata-parser-1.1.4-10.el7.x86_64.rpm yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm 

2.2 安装 rpm 包

先安装 python。

运行 rpm 命令。这里一定要加 --replacefiles --replacepkgs 参数, 因为需要覆盖一些老文件老包,不加的话会提示文件冲突或者包已经安装过了。

sudo rpm --replacefiles --replacepkgs -ivh python-backports-1.0-8.el7.x86_64.rpm python-pycurl-7.19.0-19.el7.x86_64.rpm python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch.rpm python-ipaddress-1.0.16-2.el7.noarch.rpm python-setuptools-0.9.8-7.el7.noarch.rpm python-urlgrabber-3.10-9.el7.noarch.rpm python-2.7.5-76.el7.x86_64.rpm python-iniparse-0.4-9.el7.noarch.rpm python-libs-2.7.5-76.el7.x86_64.rpm python-devel-2.7.5-76.el7.x86_64.rpm rpm-4.11.3-35.el7.x86_64.rpm python-2.7.5-76.el7.x86_64.rpm rpm-4.11.3-35.el7.x86_64.rpm rpm-python-4.11.3-35.el7.x86_64.rpm 

输出为

warning: package python-2.7.5-76.el7.x86_64 was already added, skipping python-2.7.5-76.el7.x86_64 warning: package rpm-4.11.3-35.el7.x86_64 was already added, skipping rpm-4.11.3-35.el7.x86_64 Preparing... ################################# [100%] Updating / installing... 1:python-libs-2.7.5-76.el7 ################################# [ 8%] 2:python-2.7.5-76.el7 ################################# [ 17%] 3:python-backports-1.0-8.el7 ################################# [ 25%] 4:python-pycurl-7.19.0-19.el7 ################################# [ 33%] 5:python-ipaddress-1.0.16-2.el7 ################################# [ 42%] 6:python-backports-ssl_match_hostna################################# [ 50%] 7:rpm-4.11.3-35.el7 ################################# [ 58%] 8:rpm-python-4.11.3-35.el7 ################################# [ 67%] 9:python-setuptools-0.9.8-7.el7 ################################# [ 75%] 10:python-urlgrabber-3.10-9.el7 ################################# [ 83%] 11:python-iniparse-0.4-9.el7 ################################# [ 92%] 12:python-devel-2.7.5-76.el7 ################################# [100%]


再安装 yum,同样也要加 --replacefiles --replacepkgs

sudo rpm --replacefiles --replacepkgs -ivh yum-3.4.3-161.el7.centos.noarch.rpm rpm-python-4.11.3-35.el7.x86_64.rpm yum-metadata-parser-1.1.4-10.el7.x86_64.rpm yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm rpm-4.11.3-35.el7.x86_64.rpm


输出为

Preparing... ################################# [100%] Updating / installing... 1:rpm-4.11.3-35.el7 ################################# [ 20%] 2:rpm-python-4.11.3-35.el7 ################################# [ 40%] 3:yum-metadata-parser-1.1.4-10.el7 ################################# [ 60%] 4:yum-plugin-fastestmirror-1.1.31-5################################# [ 80%] 5:yum-3.4.3-161.el7.centos ################################# [100%]


这里一定要注意,必须出现进度条 100% 的 输出,才是安装成功了。

不同版本的系统,需要的包可能不太一样,当运行安装命令时,可能会提示有一些依赖包缺失。

这种情况下,可以根据提示下载响应的依赖包,添加到 rpm -ivh 的列表中。

2.3 可以使用了

尝试运行下 yum。

yum --version 


输出为

3.4.3 Installed: rpm-4.11.3-32.el7.x86_64 at 2018-06-20 10:02 Built : CentOS BuildSystem <http://bugs.centos.org> at 2018-04-11 03:54 Committed: Panu Matilainen <pmatilai@redhat.com> at 2017-11-13 Installed: rpm-4.11.3-35.el7.x86_64 at 2019-03-07 10:09 Built : CentOS BuildSystem <http://bugs.centos.org> at 2018-10-30 19:27 Committed: Pavlina Moravcova Varekova <pmoravco@redhat.com> at 2018-06-19 Installed: yum-3.4.3-161.el7.centos.noarch at 2019-03-07 10:08 Built : CentOS BuildSystem <http://bugs.centos.org> at 2018-11-05 01:54 Committed: CentOS Sources <bugs@centos.org> at 2018-10-30 Installed: yum-plugin-fastestmirror-1.1.31-50.el7.noarch at 2019-03-07 10:08 Built : CentOS BuildSystem <http://bugs.centos.org> at 2018-10-30 22:58 Committed: Michal Domonkos <mdomonko@redhat.com> at 2018-08-24

三、python 升级小建议

  • 最好编译安装 python 包到一个独立的目录,需要使用高版本 python 时,直接指定此版本的可执行文件路径即可。

  • 千万不要删除老版本 python, yum 本身自己升级兼容可能还需要很久,当前还是会依赖系统默认的 python。