How to set Python3.5.2 as default Python version on CentOS?

后端 未结 4 1631
北恋
北恋 2020-11-28 07:21

Is there a way to set the Python 3.5.2 as the default Python version on CentOS 7? currently, I have Python 2.7 installed as default and Python 3.5.2 installed separately.

4条回答
  •  迷失自我
    2020-11-28 08:24

    I would suggest using alternatives instead.

    As super-user (root) run the following:

    # Start by registering python2 as an alternative
    alternatives --install /usr/bin/python python /usr/bin/python2 50
    
    # Register python3.5 as an alternative
    alternatives --install /usr/bin/python python /usr/bin/python3.5 60
    
    # Select which Python version to use
    alternatives --config python
    

    The last command will ask you to choose between registered/installed alternatives.

    As always, well most of the time anyways, you can check out the manual (linux man pages) using this simple command

    man alternatives
    

    Note:

    Altho this answer refers to/make use of specific Python versions, the alternatives command, it's concepts and uses remain the same regardless of version numbers. It is strongly suggested that you read/learn more about the alternatives command in order to understand how it can help you better manage and use your system. Also, there is a good chance that some will correct bad/unusual practices currently in use on their machines. I see it with a great majority of people which i introduce to the concept. Here is a link to a very good and simple explanation of the alternatives command.

提交回复
热议问题