国内企业服务器用 CentOS 系统的比较多,CentOS8 系统已经将系统默认 Python 版本调整为了 Python3,但是 CentOS7 的存量还是很大,毕竟对企业生产服务来说稳定大于一切,CentOS7 的 Python 版本还是 2.x。现在很多新软件都是用 python3 编写的,有一些甚至已经不支持 Python2 了,这时候就会报一大堆错,这里记录一下在 Linux 上将 Python2 升级到 Python3 的过程。

首先下载新版本,3.x 版本也挺多的,推荐 3.7.6 或者 3.7.5 吧。

wget https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tgz

然后解压缩

tar -zxvf Python-3.7.6.tgz

进入解压缩后的目录,安装配置

cd Python-3.7.6/
./configure

配置完成后,就可以编译了:

# make 

安装

# make install

验证是否安装成功:

# python -V
Python 2.7.5
# python3 -V
Python 3.7.6

一个是旧版本 2.x,另外一个是新版本 3.x。

设置 3.x 为默认版本

查看 Python 的路径,在 /usr/bin 下面。可以看到 python 链接的是 python 2.7,所以,执行 python 就相当于执行 python 2.7。

将原来 python 的软链接重命名:

# mv /usr/bin/python /usr/bin/python.bak

将 python 链接至 python3:

# ln -s /usr/local/bin/python3 /usr/bin/python

查看 python 版本:

# python -V
Python 3.7.6

配置 yum

升级 Python 之后,由于将默认的 python 指向了 python3,yum 不能正常使用,需要编辑 yum 的配置文件:

# vi /usr/bin/yum

将 #!/usr/bin/python 改为 #!/usr/bin/python2.7,保存退出即可。

Linux Python2 升级到 Python3的更多相关文章

  1. Python第五十一天 python2升级为python3

    Python第五十一天  python2升级为python3 公司使用的生产环境系统是centos7,所以这里以centos7系统为基础,讲解将python2升级为python3的方法 centos7 ...

  2. 自动发布工具版本从python2升级成python3后遇到的种种问题(涉及paramiko,Crypto,zipfile等等)

    从在公司实习到正式入职,一直还在被同事使用的是我写的一个自动发布工具.该工具的主要功能是:开发人员给出需要更新的代码包(zip格式),测试人员将该代码包部署到测服,这些代码包和JIRA数据库里的项目信 ...

  3. Linux Centos7之由Python2升级到Python3教程

    1.先查看当前系统Python版本,默认都是Python2.7,命令如下: [root@localhost gau]# python -V Python 2.7.5 2.安装Python3,安装方法很 ...

  4. Linux下升级安装Python-3.6.2版本

    本文主要介绍在Linux(CentOS)下将Python的版本升级为3.6.2的方法 众所周知,在2020年python官方将不再支持2.7版本的python,所以使用3.x版本的python是必要的 ...

  5. Centos Python2 升级到Python3

    1. 从Python官网到获取Python3的包, 切换到目录/usr/local/src #wget https://www.python.org/ftp/python/3.5.1/Python-3 ...

  6. Linux下升级安装Python-3.6.9版本

    1.操作系统信息  (1)cat /etc/redhat-releas (2)Red Hat Enterprise Linux Server release 6.0 (Santiago) 2.安装开发 ...

  7. Centos7 Python2 升级到Python3

    1. 从Python官网到获取Python3的包, 切换到目录/usr/local/src wget https://www.python.org/ftp/python/3.7.2/Python-3. ...

  8. centos下python2升级为python3

    1.下载 下载地址 https://www.python.org/downloads/release/python-353/ 选择"Gzipped source tarball"这 ...

  9. centos python2升级为python3 升级旧版本django

    阿里云centos python3 及django的配置 安装python3后 pip 会把下载的包安入python2.7 下面解决该问题 python3.5安装1,安装依赖包#yum install ...

随机推荐

  1. spring-cloud-sleuth/zipkin

    Spring Cloud Sleuth 一般的,一个分布式服务跟踪系统,主要有三部分:数据收集.数据存储和数据展示.根据系统大小不同,每一部分的结构又有一定变化.譬如,对于大规模分布式系统,数据存储可 ...

  2. js camelCase formatter

    js camelCase formatter 驼峰命名 转换器 'A'.charCodeAt(); // 65 'Z'.charCodeAt(); // 90 'a'.charCodeAt(); // ...

  3. iOS WebView All In One

    iOS WebView All In One WKWebView / UIWebView Swift Playground //: A UIKit based Playground for prese ...

  4. leetcode best solutions

    leetcode best solutions how to learning algorithms form the leetcode best solutions https://leetcode ...

  5. onsen & UI & vue & mobile UI

    onsen & UI vue & mobile UI $ npm i onsenui vue-onsenui # OR $ npm i -S onsenui vue-onsenui h ...

  6. how to check website offline status in js

    how to check website offline status in js https://developer.mozilla.org/en-US/docs/Web/API/Navigator ...

  7. npm & cli & cp: no such file or directory

    npm & cli & cp: no such file or directory empty files bug https://npm.runkit.com/hui-cli htt ...

  8. web effects collection

    web effects collection typewriter effect js 打字机效果 http://www.mattboldt.com/demos/typed-js/ https://g ...

  9. ORM & sequelize

    ORM Object Relational Mapping 对象关系映射 Table => Object, 简化 SQL 查询命令的编写 https://en.wikipedia.org/wik ...

  10. input number css hidden arrow

    input number css hidden arrow show arrow OK input[type="number"]::-webkit-inner-spin-butto ...