CentOS system default python version python2 replaced by the python3

One. OK

  If you installed the CentOS yum, generally there will be a version of python2. Command line, type python, appearing python2 environment:

[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.

  We want to connect the python command to the version of the shell of python3. First herein means python3, then connect to the python python3.

  Since the path to the file's PATH bash_profile, so no need to change the environment variable. If you do not love to Tianjin oh environment variables you need

  vim ~/.bash_profile

  The path Python3 plus, and then reload this file bash_profile

  Then modify this file bashrc

vim ~/.bashrc

  The path python3 python2 and wrote all the words, and python designated as python3

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

  In this way, the command line is open python3 a python.

[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.  

  note:

  In centos, the software installation instructions for yum is to call the python command interpreter last night, so the default version Python2, if the change python3, due to compatibility issues 2 and 3 resulted yum may be faulty. Therefore require special attention.

  yum path in

/usr/bin/yum

  Yum you can look at the file

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

  It can be seen at the beginning of the default interpreter for the / usr / bin / python. If yum because the amendment python interpreter appeared bug, this can be changed /usr/bin/python2.x can be.

 

Guess you like

Origin www.cnblogs.com/tjp40922/p/11351501.html