-4

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?

4
  • 3
    Because 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 and this one, too. As to why it is so picky, I don't know.
    – cocomac
    Feb 4, 2022 at 5:40
  • 3
    Many 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 4, 2022 at 5:40
  • 1
    The 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 4, 2022 at 6:11
  • 2
    Don'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. anaconda.com/products/individual, docs.conda.io/en/latest/miniconda.html Feb 4, 2022 at 8:12

1 Answer 1

-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
3
  • 2
    People 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 4, 2022 at 22:38
  • If you want to install pip for python 3.9, you can use this answer. However, the OP wasn't asking that so we cannot assume they are ignorant of this.
    – mchid
    Feb 4, 2022 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. Feb 13, 2022 at 6:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .