python 升级_Centos 7 升级 Python 与 Yum 修改

17e4e098910660b66d0f7f6d0ddb7610.png

公司项目需要线上服务器需要升级 Python 版本到 3.7.5,升级后 yum 还需要正常使用,这个感觉是很简单的事情,但有些同学还是没有搞定,现把之前遇到过的问题,简单罗列下。

1.  官网下载软件包

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

2.  Python-3.7.5默认编译安装,不需要安装 pip,需要修改下源码

# 进入解压目录查看这个文件
Modules/Setup.dist# 把下面这行前面的注释去掉
zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz

3.   安装依赖包(这一步很重要)

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel libffi-devel

4. 常见错误(其实错误有很多,这里把经常遇到的给大家罗列下)

# 错误一
zipimport.ZipImportError: can‘t decompress data; zlib not available

# 错误二
Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available)

# 错误三
ModuleNotFoundError: No module named '_ctypes'

错误一需要安装zlib-devel, 错误二需要安装openssl-devel、错误三需要安装libffi-devel等,所以第3步的依赖包,一定要安装,不然后面遇到问题还需要重新编译 Python。

5.  编译安装

./configure --prefix=/usr/local/python375 && make && make install

6.  升级并覆盖老版本

mv /usr/bin/python /usr/bin/python_old
ln -s /usr/local/python375/bin/python3 /usr/bin/python
ln -s /usr/local/python375/bin/pip3 /usr/bin/pip

7.  升级 pip

pip install --upgrade pip

8.  批量安装测试

pip install -r requirement.txt -i https://pypi.douban.com/simple/

9. 单个包安装测试

pip install zipp==0.6.0 -i https://pypi.douban.com/simple/

10.  修改 yum

# 修改一,这里修改成python2.7
[root@localhost ~]# cat /usr/bin/yum | more
#!/usr/bin/python2.7


# 修改二,这里也修改成python2.7
[root@localhost ~]# cat /usr/libexec/urlgrabber-ext-down | more
#! /usr/bin/python2.7

11. yum 测试

[root@localhost ~]# yum -y install ipvsadm
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.huaweicloud.com
Resolving Dependencies
--> Running transaction check
---> Package ipvsadm.x86_64 0:1.27-7.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================================================
 Package Arch Version Repository Size
==================================================================================================================================================
Installing:
 ipvsadm x86_64 1.27-7.el7 base 45 k

Transaction Summary
==================================================================================================================================================
Install 1 Package

Total download size: 45 k
Installed size: 75 k
Downloading packages:
ipvsadm-1.27-7.el7.x86_64.rpm | 45 kB 00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : ipvsadm-1.27-7.el7.x86_64 1/1 
  Verifying : ipvsadm-1.27-7.el7.x86_64 1/1 

Installed:
  ipvsadm.x86_64 0:1.27-7.el7

Complete!
[root@localhost ~]#

12. 总结 

最基础的安装步骤,但很多高 level 的同学也搞不定,其实越简单的东西越体验一个人的基础能力,共勉。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值