When you install Debian Linux, the installation process may provide you with multiple available Python versions at the same time. Therefore, the system will have multiple executable binary files of Python. Generally, the default Python version of Ubuntu is 2.x. how can I change the default Python version? Let's take a look. You can use the ls command in the following ways to view the Python binary files in your system.
$ ls /usr/bin/python*/usr/bin/python /usr/bin/python2 /usr/bin/python2.7 /usr/bin/python3 /usr/bin/python3.4 /usr/bin/python3.4m /usr/bin/python3m
Run the following command to view the default Python version:
$ python --versionPython 2.7.8
1. modify the Python version based on the User:
To modify the Python version for a specific user, you only need to create an alias (alias) in the home directory. Open this user's ~ /. Bashrc file, add new alias information to modify the default Python version.
alias python='/usr/bin/python3.4'
After completing the preceding operations, log on again or reload the. bashrc file to make the operation take effect.
$ . ~/.bashrc
Check the current Python version.
$ python --versionPython 3.4.2
2. modify the Python version at the system level.
We can use update-alternatives to change the Python version for the entire system. Log on as a root user. first, list all available python alternative versions:
# update-alternatives --list pythonupdate-alternatives: error: no alternatives for python
If the preceding error message is displayed, the replacement version of Python has not been recognized by the update-alternatives command. To solve this problem, we need to update the alternative list and put python2.7 and python3.4 in it.
# update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in auto mode# update-alternatives --install /usr/bin/python python /usr/bin/python3.4 2update-alternatives: using /usr/bin/python3.4 to provide /usr/bin/python (python) in auto mode
The -- install option uses multiple parameters to create symbolic links. The last parameter specifies the priority of this option. if we do not manually set an alternative option, the option with the highest priority will be selected. In this example, the priority set for/usr/bin/python3.4 is 2, so the update-alternatives command automatically sets it to the default Python version.
# python --versionPython 3.4.2
Next, we will list available alternative Python versions.
# update-alternatives --list python/usr/bin/python2.7/usr/bin/python3.4
Now, we can use the command below to switch between the listed Python replicas at any time.
# update-alternatives --config python
# python --versionPython 2.7.8
3. remove the alternative version
Once a Python replacement version no longer exists in our system, we can delete it from the update-alternatives list. For example, we can remove python2.7 from the list.
# update-alternatives --remove python /usr/bin/python2.7 update-alternatives: removing manually selected alternative - switching python to auto modeupdate-alternatives: using /usr/bin/python3.4 to provide /usr/bin/python (python) in auto mode
Method 2: Remove a soft connection
rm -rf /data/logs ln -s /temp/logs /data/logs
Solve the soft connection ln error-bash:/usr/local/bin/mysql: Too many levels of symbolic links
Summary
The above is all about this article. I hope this article will help you in your study or work. if you have any questions, please leave a message.
For more information about how to change the default python version of Ubuntu, see python> Anaconda!