How to set default python3 to python 3.9 instead of python 3.8 in Ubuntu 20.04 LTS

We Are Going To Discuss About How to set default python3 to python 3.9 instead of python 3.8 in Ubuntu 20.04 LTS. So lets Start this Python Article.

How to set default python3 to python 3.9 instead of python 3.8 in Ubuntu 20.04 LTS

  1. How to solve How to set default python3 to python 3.9 instead of python 3.8 in Ubuntu 20.04 LTS

    You should be able to use python3.9 -m pip install <package> to run pip with a specific python version, in this case 3.9.
    The full docs on this are here: https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/
    If you want python3 to point to python3.9 you could use the quick and dirty.
    alias python3=python3.9
    EDIT:
    Tried to recreate your problem,
    # which python3 /usr/bin/python3 # python3 --version Python 3.8.10 # which python3.8 /usr/bin/python3.8 # which python3.9 /usr/bin/python3.9
    Then update the alternatives, and set new priority:
    # sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1 # sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2 # sudo update-alternatives --config python3 There are 2 choices for the alternative python3 (providing /usr/bin/python3). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/bin/python3.9 2 auto mode 1 /usr/bin/python3.8 2 manual mode * 2 /usr/bin/python3.9 2 manual mode Press <enter> to keep the current choice[*], or type selection number: 0
    Check new version:
    # ls -alith /usr/bin/python3 3338 lrwxrwxrwx 1 root root 25 Feb 8 14:33 /usr/bin/python3 -> /etc/alternatives/python3 # python3 -V Python 3.9.5 # ls -alith /usr/bin/pip3 48482 -rwxr-xr-x 1 root root 367 Jul 13 2021 /usr/bin/pip3 # pip3 -V pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.9)
    Hope this helps (tried it in wsl2 Ubuntu 20.04 LTS)

  2. How to set default python3 to python 3.9 instead of python 3.8 in Ubuntu 20.04 LTS

    You should be able to use python3.9 -m pip install <package> to run pip with a specific python version, in this case 3.9.
    The full docs on this are here: https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/
    If you want python3 to point to python3.9 you could use the quick and dirty.
    alias python3=python3.9
    EDIT:
    Tried to recreate your problem,
    # which python3 /usr/bin/python3 # python3 --version Python 3.8.10 # which python3.8 /usr/bin/python3.8 # which python3.9 /usr/bin/python3.9
    Then update the alternatives, and set new priority:
    # sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1 # sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2 # sudo update-alternatives --config python3 There are 2 choices for the alternative python3 (providing /usr/bin/python3). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/bin/python3.9 2 auto mode 1 /usr/bin/python3.8 2 manual mode * 2 /usr/bin/python3.9 2 manual mode Press <enter> to keep the current choice[*], or type selection number: 0
    Check new version:
    # ls -alith /usr/bin/python3 3338 lrwxrwxrwx 1 root root 25 Feb 8 14:33 /usr/bin/python3 -> /etc/alternatives/python3 # python3 -V Python 3.9.5 # ls -alith /usr/bin/pip3 48482 -rwxr-xr-x 1 root root 367 Jul 13 2021 /usr/bin/pip3 # pip3 -V pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.9)
    Hope this helps (tried it in wsl2 Ubuntu 20.04 LTS)

Solution 1

You should be able to use python3.9 -m pip install <package> to run pip with a specific python version, in this case 3.9.

The full docs on this are here: https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/

If you want python3 to point to python3.9 you could use the quick and dirty.

alias python3=python3.9

EDIT:

Tried to recreate your problem,

# which python3
/usr/bin/python3
# python3 --version
Python 3.8.10
# which python3.8
/usr/bin/python3.8
# which python3.9
/usr/bin/python3.9

Then update the alternatives, and set new priority:

# sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1
# sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
# sudo update-alternatives --config python3
There are 2 choices for the alternative python3 (providing /usr/bin/python3).

  Selection    Path                Priority   Status
------------------------------------------------------------
  0            /usr/bin/python3.9   2         auto mode
  1            /usr/bin/python3.8   2         manual mode
* 2            /usr/bin/python3.9   2         manual mode

Press <enter> to keep the current choice[*], or type selection number: 0

Check new version:

# ls -alith /usr/bin/python3
3338 lrwxrwxrwx 1 root root 25 Feb  8 14:33 /usr/bin/python3 -> /etc/alternatives/python3
# python3 -V
Python 3.9.5
# ls -alith /usr/bin/pip3
48482 -rwxr-xr-x 1 root root 367 Jul 13  2021 /usr/bin/pip3
# pip3 -V
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.9)

Hope this helps (tried it in wsl2 Ubuntu 20.04 LTS)

Original Author MrWorldWide Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment