一.了解

  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. spring学习笔记四:spring常用注解总结

    使用spring的注解,需要在配置文件中配置组件扫描器,用于在指定的包中扫描注解 <context:component-scan base-package="xxx.xxx.xxx.x ...

  2. JavaScript小数转百分比

    在浏览器的控制台操作0.28*100会得到28.000000000000004这样一个不太精确的值 进行转换 toPercent(point){ let str = Number(point * 10 ...

  3. com.spotify:docker-maven-plugin 报localhost:2375 Connection refused 错误

    当用maven build项目时出现了如下错误: Failed to execute goal com.spotify:docker-maven-plugin:0.4.13:build (defaul ...

  4. C++笔试常见问题

    C++提供的编译预处理功能主要有以下三种: 宏定义 文件包含 条件编译 预编译又称为预处理 , 是做些代码文本的替换工作.处理#开头的指令 , 比如拷贝 #include包含的文件代码, #defin ...

  5. mysql中not exists的简单理解

    http://www.cnblogs.com/glory-jzx/archive/2012/07/19/2599215.html http://sunxiaqw.blog.163.com/blog/s ...

  6. js 实现排序算法 -- 选择排序(Selection Sort)

    原文: 十大经典排序算法(动图演示) 选择排序(Selection Sort) 选择排序(Selection-sort)是一种简单直观的排序算法.它的工作原理:首先在未排序序列中找到最小(大)元素,存 ...

  7. Android 粘合剂'Binder'

    背景知识 要详细掌握Android 的Binder通信机制需要先提前了解一些通信原理与Linux系统的基础知识. RPC RPC(Remote Procedure Call),即远程过程调用,也被称为 ...

  8. stat()函数--------------获取文件信息

    stat():用于获取文件的状态信息,使用时需要包含<sys/stat.h>头文件. 函数原型:int stat(const char *path, struct stat *buf): ...

  9. sycCMS PHP V1.0---呵呵呵呵呵

    闲的无聊,随便找了份代码看了看. //search.php 第17行 第49行 ...... $keyword=SafeRequest("keyword","post&q ...

  10. ES6学习笔记之变量的解构赋值

    变量的解构赋值 ES6允许按照一定模式,从数组和对象中提取值,对变量进行赋值,这被称为解构. 数组的解构赋值 以前,为变量赋值,只能直接指定值: 1 2 3 var a = 1; var b = 2; ...