一.了解

  CentOS中如果安装有yum,一般会有python2的某个版本。命令行键入python,出现的python2的环境:

[root@instance-hrnebyqu src]# python
Python 2.7.5 (default, Apr 11 2018, 07:36:10)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

  我们希望将python这个shell指令连接到python3的版本。这里首先装python3,然后将python连接到python3上。

  由于路径添加到了bash_profile文件中的PATH中了,因此环境变量不需要再改了。如果没有天津爱到哦环境变量则需要

  vim ~/.bash_profile

  把Python3的路径加上,然后重载bash_profile这个文件

  接着修改bashrc这个文件

vim ~/.bashrc

  将python2和python3 的路径都写上,并将python指定为python3

alias python2=/usr/bin/python
alias python3=/usr/local/python3/bin/python3
alias python=/usr/local/python3/bin/python3

  这样,命令行开python就是python3了。

[root@instance-hrnebyqu src]# python
Python 3.6.6 (default, Jul 4 2019, 12:00:29)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.  

  注意:

  在centos中,用于软件安装的yum指令是调用python昨晚命令解释器的,因此其默认版本为Python2,如果改成python3,会由于2和3的兼容性问题导致yum可能出现故障。因此需要特别注意。

  yum 的路径在

/usr/bin/yum

  可以看一下yum文件

#!/usr/bin/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:

  可以看到,开头默认了解释器为/usr/bin/python。如果yum因为修改了python解释器出现bug,可以将这个改成/usr/bin/python2.x即可。

CentOS系统python默认版本由python2改为python3的更多相关文章

  1. Linux系统中python默认版本为python2.7,修改为python3 项目上传码云

    # 查询系统本系统中安装的python版本 ls -l /usr/bin/python* 1.在虚拟机上新建虚拟环境 # 系统中python默认版本为python2.,可以将其修改为python3 # ...

  2. 切换Ubuntu系统python默认版本的方法

    另附切换系统python默认版本的方法: 先使用命令: update-alternatives --list python 查看python命令的各种可能结果, 例如我的结果: /usr/bin/py ...

  3. Python多版本安装 Python2.7和Python3.5

    声明:本文仅仅在win8.1测试通过! 1.下载 Python2.7,3.5 2.依次安装Python27(c:\Python27)  Python35(c:\Python35) 3.c:\Pytho ...

  4. 在windows系统电脑上同时安装python2.x和python3.x版本

    在同一个电脑机子(windows系统)上安装同时安装python2.x和python3.x版本. 一.python2.x和python3.x安装 步骤1:在python官网(https://www.p ...

  5. Python默认版本修改

    Python默认版本修改 当电脑安装了多个版本的Python,而Shell中默认的Python不是你想要的,这个时候就需要对Python的默认版本进行修改. 在Windows中,可以通过修改环境变量的 ...

  6. 修改CentOS系统的默认启动级别

    ======修改CentOS系统的默认启动级别====== 现在的Linux系统安装完后就运行在第5个级别,即系统启动后直接进入图形界面,而不用在字符模式下登录后用startx或者xinit来起动图形 ...

  7. Mac安装Python3后,如何将默认执行的Python2改为Pyhton3

    Mac 笔记本电脑系统自带的Python版本一般是Python 2.7,如果安装了Python 3.x,在终端中输入python命令后,输出的信息还是Python 2.7,问题就是如何将Mac系统默认 ...

  8. Python默认版本切换

    Mac上自带python2.7 版本,但是我又下了一个3.7版本(下载的版本默认安装在 /Library/Frameworks/Python.framework/Versions/3.7/bin/py ...

  9. Linux下python默认版本切换成替代版本

    本文链接自http://www.myhack58.com/Article/48/66/2016/71806.htm 当你安装 Debian Linux 时,安装过程有可能同时为你提供多个可用的 Pyt ...

随机推荐

  1. LeetCode Day 3

    LeetCode0003 给定一个字符串,请你找出其中不含有重复字符的最长子串的长度. 示例 1: 输入: "abcabcbb" 输出: 3 解释: 因为无重复字符的最长子串是 & ...

  2. win10安装inventor失败,怎么强力卸载删除注册表并重新安装

    一些搞设计的朋友在win10系统下安装inventor失败或提示已安装,也有时候想重新安装inventor的时候会出现本电脑windows系统已安装inventor,你要是不留意直接安装invento ...

  3. Java - 面向对象练习 - market

    Marketpackage market; public class Market {    private String marname;    private Product[] producta ...

  4. Mercurial 小结

    基本操作 # 拉取 并 更新 pull pull && hg update # 撤销上一个命令(不能重复运行) hg rollback # 恢复到指定的 changeset hg st ...

  5. [Gem] AASM 狀態機

    @(Ruby on Rails)[rails, gem] 1234 # AASM is a continuation of the acts-as-state-machine rails plugin ...

  6. Angular4——7.表单处理

    在Angular中存在两种表单处理方式: 模版驱动式表单 表单的数据模型是通过组件模版中的相关指令来定义的.由于使用这种方式定义表单的数据模型时,我们会受限于HTML的语法,所以,模版驱动方式只适用于 ...

  7. Docker实战之Redis-Cluster集群

    概述 接上一篇Docker实战之MySQL主从复制, 这里是Docker实战系列的第二篇,主要进行Redis-Cluster集群环境的快速搭建.Redis作为基于键值对的NoSQL数据库,具有高性能. ...

  8. Requests功能整理

    import requests # GET r = requests.get('https://api.github.com/events') # POSTr = requests.post('htt ...

  9. Canvas 使用及应用

    Canvas canvas 是 HTML5 当中我最喜欢的所有新特性中我最喜欢的一个标签了.因为它太强大了,各种有意思的特效都可以实现. 1. canvas 的基本使用方法 - 它是一个行内块元素 - ...

  10. 使用cookie

    概述 虽说在现代Web开发过程中讨论Cookie有些不合时宜,但是这是开发人员如今可以使用的最古老.最稳定的客户端存储形式.当然,我们并不推荐使用Cookie,只是说它是一种选择. Cookie于19 ...