Change the default Python version of Ubuntu

Change the default Python version of Ubuntu

 

Which version of Python First of all there is to see in the system

 

  • ls /usr/bin/python

     

View the current python version

  • python --version

     

Based on the user to modify the default version

  • Python version you want to modify a specific user, only need to create an alias (alias) can be in their home directory. Open ~ / .bashrc file for the user, add a new alias information to modify the default version of Python used.
  • alias python='/usr/bin/python3.6'

     

  • Once done, log in again or reload the .bashrc file, make the operation effective.
  • . ~/.bashrc

     

At the system level modified version of Python

  • Use update-alternatives to change the version of Python for the entire system. Log in as root, first proceed to list all of the available python alternative version information:
  • update-alternatives --list python

     

 

update-alternatives: error: no alternatives for python
  • If the error message shown above appears, the alternative versions of the Python command update-alternatives have not been identified. Want to solve this problem, we need to update the look instead of a list, will python2.7 and python3.6 in it.
  • update-alternatives --install /usr/bin/python python /usr/bin/python2.7
    update-alternatives --install /usr/bin/python python /usr/bin/python3.6

     

  • --install option uses a number of parameters to create a symbolic link. The last parameter specifies the priority of this option, if we do not have to manually set up an alternative option, the option with the highest priority will be selected. In this example, we set the priority /usr/bin/python3.6 2, the update-alternatives command will automatically set it as the default version of Python.
  • python --version

    At this time, check the version already python 3.6

 

  • Next, we list the Python alternative versions available again.
  • update-alternatives --list python
    
    /usr/bin/python2.7
    /usr/bin/python3.6

     

  • Now, we can use the command below at any time in Python alternative versions listed in any switched.
  • update-alternatives --config python

     

Removed alternate versions

  • Once a Python alternative versions of our system no longer exists, we can be removed from the list of update-alternatives. For example, we can release the list of removed python2.7 out.
  • update-alternatives --remove python /usr/bin/python2.7

     

  • Method 2, to remove soft connection
  • rm -rf /data/logs
     
    
    ln -s /temp/logs /data/logs

     

 

Guess you like

Origin www.cnblogs.com/zhx-blog/p/11619750.html