When I install python3.9 or 3.10, there is no change in python3 command. It is still python3.8.10 and all packages will be installed for 3.8.10 unless I run a python3.9 -m pip. What is the reason that you cannot change python3 version to a newer one?
Asked
Active
Viewed 735 times
-4
-
3Because it will break Ubuntu if you replace the old one completely. Ubuntu is very picky about which version of Python is the default. See [this question](https://askubuntu.com/questions/1132349/terminal-not-opening-up-after-upgrading-python-to-3-7) and [this one](https://askubuntu.com/q/384033/1438484), too. As to _why_ it is so picky, I don't know. – cocomac Feb 04 '22 at 05:40
-
3Many Ubuntu tools rely on `python3` and work with the version the system comes with. If you change the *default* version, those Ubuntu tools may cease working, or may cease working reliably, thus protections on keeping the default version correct. You didn't say if desktop or server, but you should avoid making changes to the default python3 unless you're fully aware of those consequences. – guiverc Feb 04 '22 at 05:40
-
1The OS depends on the standard python version. However, you can set an alias for your user as mentioned below. Don't forget to log out and back in after you set the alias or run `source ~/.bashrc` to apply the changes. – mchid Feb 04 '22 at 06:11
-
2Don't mess up with the default python version. If something goes wrong, you may have to reinstall Ubuntu. Use Anaconda/Miniconda instead. It will set up an isolated python environment for you. https://www.anaconda.com/products/individual, https://docs.conda.io/en/latest/miniconda.html – Archisman Panigrahi Feb 04 '22 at 08:12
1 Answers
-1
The reason you cannot change python3 to a newer default version is because it would break the operating system and many applications that depend on the default version of python3. You can, however, use an alias so that, when you run the python command in the terminal, python3.9 will execute.
Open the bashrc file by using the following command:
nano ~/.bashrc
Add the following line to the below of the bashrc file .
alias python3='/usr/bin/python3.9'
After you save the file, run the following command to apply the changes:
. ~/.bashrc
-
2People may want to explain the downvotes to the author. Simply setting this as an alias is a safe alternative recommended by many other upvoted answers on other similar questions. If you have a problem running the command with `sudo` I suggest you ask a separate question or leave a comment because there is a fix for that and it has nothing to do with `python`. It's not typically recommended to install `pip` packages system wide anyhow. – mchid Feb 04 '22 at 22:38
-
If you want to install pip for python 3.9, you can use [this answer](https://askubuntu.com/questions/1331391/how-do-you-install-pip-for-python3-9-4?rq=1). However, the OP wasn't asking that so we cannot assume they are ignorant of this. – mchid Feb 04 '22 at 22:43
-
The default Python version used for script execution can be changed, but it cannot be changed system-wide (mentioned in previous comment) because certain components of Ubuntu depend on specific Python installations. – JerryWill321 Feb 13 '22 at 06:12