How do I install Python 3.8 in Lubuntu 18.04?

I downloaded Lubuntu LTS 18.04 and there is Python 3.6.9 IDLE which is built-in. But since it is very old, I want to update to 3.8. How do I do that?


Solution 1:

This post is community wiki so as to not claim the credit of @Kulfy's comment. This procedure worked on Ubuntu 18.04.

DON'T EVER CHANGE DEFAULT PYTHON!!! It may cause your system to break and some applications won't even run. It's far far far better to invoke python3.8 using python3.8 command

When installing python3.8, do the following

$ sudo apt-get install python3.8 python3.8-dev python3.8-distutils python3.8-venv

For most people this will be acceptable as they will be using a virtual environment for development. Construct a virtual environment and activate it as you usually would. This will leave you in a terminal where python resolves to python3.8:

$ python3.8 -m venv dev3.8/
$ source dev3.8/bin/activate
(dev3.8) $ which python
...dev3.8/bin/python
(dev3.8) $ python --version
Python 3.8.0

Neglecting to install python3.8-venv will result in an unhelpful error, that suggests you should install python-venv which resolves to python3.6-venv:

$ python3.8 -m venv dev3.8/
The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.

    apt-get install python3-venv

You may need to use sudo with that command.  After installing the python3-venv
package, recreate your virtual environment.

Failing command: ... (trimmed for formatting)

Solution 2:

Step 1: Install the latest version of python. Currently, 3.8 is the latest

sudo apt install python3.8

Step 2: Add Python 3.6 & Python 3.8 to update-alternatives

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6.9
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8.1

Step 3: Update Python 3 to point to Python 3.7

By default, Python 3.6 is pointed to Python 3. So, we run python3 it will execute as python3.6 but we want to execute this as python3.8

sudo update-alternatives --config python3

versions You should get a similar output. Now type 2 and hit enter for Python 3.

Step 4: Test the version of python

Finally test the current version of python by typing

python3 -V

Solution 3:

  1. Run the following commands as root or user with sudo access to update the package list and install the prerequisites:

    sudo apt update
    sudo apt install software-properties-common
    
  2. Add the deadsnakes PPA to your sysmtem's source list:

    sudo add-apt-repository ppa:deadsnakes/ppa
    
  3. Install Python 3.8 with following command:

    sudo apt install python3.8
    
  4. Verify the installation:

    python3.8 --version