how to upgrade python3.5 to python3.6 in Virtual Machine?

Question:

I have a virtual machine (Azure):

vm:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.6 LTS
Release:        16.04
Codename:       xenial

It is installed with Python 3.5.6, and I would like to upgrade it to 3.6 to be compatible with some libraries. I have tried the following:

vm:~$ python --version
Python 3.5.6 :: Anaconda, Inc.
vm:~$ sudo apt-get install python3.6
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python3.6
E: Couldn't find any package by glob 'python3.6'
E: Couldn't find any package by regex 'python3.6'
vm:~$ sudo apt-get upgrade python3.6
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python3.6
E: Couldn't find any package by glob 'python3.6'
E: Couldn't find any package by regex 'python3.6'

May I know how to go about doing it?

Can I do it from JupyterLab also?

Asked By: perpetualstudent

||

Answers:

Here’s a suggestion:

Follow this https://askubuntu.com/questions/865554/how-do-i-install-python-3-6-using-apt-get/865569#865569

$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt-get update
$ sudo apt-get install python3.6

If there are problems with update, check this https://www.xmodulo.com/how-to-fix-apt-get-update-error-on-ubuntu.html#:~:text=This%20error%20can%20happen%20when,%22%20apt%2Dget%20update%20%22.

$ sudo rm -rf /var/lib/apt/lists/*
$ sudo apt-get update
$ sudo apt-get upgrade python3.6

After that, do the following in JupyterLab (OS: Ubuntu 16.04 xenial)

Upgrade pip:

!pip install --upgrade pip

Install virtual environment:

!pip install virtualenv

Create new kernel with Python3.6:

!virtualenv -p python3.6 Python_3_6

Create a new kernel option:

!python -m ipykernel install --user --name=Python_3_6

This would create a new kernel option with the name Python_3_6 in the menu when starting a new notebook. Now this new kernel would be compatible to run those libraries you need!

Answered By: MiH