Seven Claws Source Code: Switching Between Python 2 and Python 3 on Ubuntu 20.04 WSL

thumbnail

Many of us use the latest version of Python, but some older version keywords are no longer supported. Alternatively, you may have an older version of Python installed on WSL and continue to use it to write code in the newer version of Python. Today we will switch/install the latest version of Python on your WSL Ubuntu 20.04.

Install

To install the latest Python 3 version in the Ubuntu terminal, just type the following command:

> > sudo apt install python3 >

Once installed, run this command to check your Python version.

> > python3 --version >

Switch Python version

Verify each Python version installed on the system. To do this, we have to check the /bin directory. This is due to Python 3's ability to support variants. Let's use Python 3.7 and 3.8. The -version command is not helpful in these cases because it only displays the currently specified version.

execute this command

> > ls /usr/bin/python* >

After listing each version on the system, we must determine if a Python alternative is configured.

execute this command

> > sudo update-alternatives --list python >

Now we will configure two Python alternatives

execute this command

> > $ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1 >

> > $ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2 >

The Python option set and its use must be validated. Now we have to select the Python 3 version by typing the selection number corresponding to the Python 3 version.

execute this command

> > sudo update-alternatives --config python >

To check python version just use this command

> > python --version >

Latest Programming News and Information | GeekBar

Related Posts