Recently installed in Ubuntu16.04 python3.5 and the system comes with the python2.7.13, summarize the different versions of the switching problem.
- Alias: Aliases
- BASHRC: Personal Profile
First, modify the Python version (for users)
To modify a Python version for a particular user, simply create one (alias) in its home directory alias
. Open the user's ~/.bashrc
file and add the new alias information to modify the Python version that is used by default.
Alias python= '/usr/bin/python3.5 '
Once you have done this, log back in or reload .bashrc
the file for the operation to take effect.
. ~/.bashrc
Check the current Python version.
Python--version
Second, modify the Python version (for the entire system)
The Python version can be modified throughout the system level with the Update-alternatives directive. The premise is to log in as the root user.
sudo passwd root
Prompt: Enter new UNIX password:, enter the password as required, so that the activation is completed, sudo again-, login completed.
- Su
- SU//Switch to Super User
- Su username//switch to username user
- Su differs from sudo su: refer here.
After logging in to the root user, view all versions of Python:
Update-alternatives
If an error message appears:
Update-alternatives:error:no Alternatives for Python
This shows that Python alternatives is not update-alternatives recognized, and we need to update alternatives table to include Python 2.7 and python3.5.
update-alternatives:using/usr/bin/python2.7 to Provide/usr/bin/python (python) in Auto modeupdate-alternatives:using /usr/bin/python3.5 to Provide/usr/bin/python (python) in auto mode
This time the computer tip:syntax error near unexpected token ' (', which is not recognized (, need to be escaped:
update-alternatives:using/usr/bin/python2.7 to Provide/usr/bin/python \ (python\) in Auto modeupdate-alternatives: using/usr/bin/python3.5 to Provide/usr/bin/python \ (python\) in Auto mode
It also indicates an error:
No command ' update-alternatives: ' Found, did you mean:
Command ' update-alternatives ' from the package ' dpkg ' (main)
Update-alternatives:: Command not found
not resolved temporarily.
Reference:
- Https://linuxconfig.org/how-to-change-from-default-to-alternative-python-version-on-debian-linux
Two versions of Python under Ubuntu toggle