CentOS 7下Python 2.7升级至Python3.6.1的实战教程
作者:bladestone 时间:2023-09-13 07:56:46
前言
大家应该都知道,Centos是目前最为流行的Linux服务器系统,其默认的Python 2.x,但是根据python社区的规划,在不久之后,整个社区将向Python3迁移,且将不在支持Python2, 那该如何平滑迁移至Python3 呢?
1. 环境介绍
Centos 7, 当前的Python版本2.7.12
>> uname -a
Linux AY131203102210033c39Z 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
>> cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
二、下载Python 3.x的安装包
默认linux的安装包只能是源码安装:
>> wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
由于xz结尾的文件,故可以使用如下命令来解压:
>> xz -d Python-3.6.1.tar.xz
>> tar xvf Python-3.6.1.tar
三、 编译并安装
>> mkdir /usr/local/python3
>> cd Python-3.6.1 #进入源码文件目录
>> sudo ./configure --prefix=/usr/local/python3 --enable-optimizations
>> sudo make # 此过程将持续较长的时间
四、 替换python
>> cd /usr/bin
>> mv python python.bak
其中有python, python2.7, python2三个文件,其实都是指向python2.7的,这里将python备份
>> sudo ln -s /usr/local/python3/bin/python3.6 /usr/bin/python
>> python -V
检查python的版本是否被正确替换掉了。
五、收尾替换工作
原则: 所有python相关的应用,如果为使用/usr/bin/python开头的脚本统统替换掉, 如果其只能在python2.7下执行,则替换为python2.7。
根据网路上的信息,相关的文件可能有如下, 具体情况视具体情况而定:
a. /usr/bin/yum
b./usr/libexec/urlgrabber-ext-down
总结
过程比较简单,期待Centos7尽快升级到Python3.
好了,以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对脚本之家的支持。
来源:http://blog.csdn.net/blueheart20/article/details/70062671
标签:centos7,python2.7,python3.6.1
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
如何让页面在打开时自动刷新一次让图片全部显示
2024-04-17 10:10:44
利用python爬取斗鱼app中照片方法实例
2022-01-03 17:40:39
![](https://img.aspxhome.com/file/2023/9/75879_0s.png)
php session安全问题分析
2023-11-15 06:45:29
python fire库的使用实例教程
2023-08-24 14:01:22
![](https://img.aspxhome.com/file/2023/0/61760_0s.png)
Layer UI表格列日期格式化及取消自动填充日期的实现方法
2024-04-22 13:02:22
![](https://img.aspxhome.com/file/2023/8/135968_0s.png)
PL/SQL中编写Oracle数据库分页的存储过程
2024-01-16 08:50:24
![](https://img.aspxhome.com/file/2023/5/65265_0s.jpg)
Python中顺序表原理与实现方法详解
2023-03-24 22:57:48
asp如何在聊天室实现趣味答题并计分功能?
2010-06-18 20:00:00
MySQL中常见的八种SQL错误用法示例
2024-01-25 18:40:00
使用setup.py安装python包和卸载python包的方法
2023-01-31 02:20:47
PHP 面向对象程序设计(oop)学习笔记 (二) - 静态变量的属性和方法及延迟绑定
2024-06-05 15:42:03
用户体验设计中用到的统计学方法
2009-07-12 08:26:00
只用50行Python代码爬取网络美女高清图片
2023-08-29 07:45:51
![](https://img.aspxhome.com/file/2023/6/128726_0s.png)
Python魔术方法专题
2023-03-14 15:38:02
python中list列表的高级函数
2021-02-24 08:21:14
python使用fork实现守护进程的方法
2021-08-27 00:37:50
使用Python制作自动推送微信消息提醒的备忘录功能
2023-02-26 18:19:40
![](https://img.aspxhome.com/file/2023/3/112393_0s.jpg)
Python selenium get_cookies获取cookie不全的解决方案
2021-09-17 07:39:52
![](https://img.aspxhome.com/file/2023/9/103499_0s.jpg)
Golang 高效排序数据详情
2023-06-23 08:23:41
![](https://img.aspxhome.com/file/2023/6/87626_0s.jpg)
Python subprocess库六个实例快速掌握
2021-02-22 05:53:56