Jupyter lab: how to use different versions of Python

Installing Jupyter lab

If you have jupyter notebook, but you do not have jupyter lab, you can install it like this:

pip install jupyterlab

from the windows 10 command line or Powershell.

Image result for powershell

Image result for powershell pip install
Write here pip install jupyterlab

Once you installed it, you can run Jupyter lab from any folder, writing in powershell:

jupyter lab

Then, something like this will appear.

Jupyter lab

How to use a different version of Python in Jupyter lab

Jupyter lab, evolution of Jupyter notebook is a great tool to use Python code inside the browser, with a lot of enhancement that you can use to join coding in Python with markdown and with the chance to use html and also javascript inside the same page to better explain what you are doing with the code. It is a sort of IDE inside the browser that can also show inside the page widgets, graphics from matplotlib, tables from pandas etc.

Image result for jupyter lab

Running different version on Python in Jupyter lab

You could have different versions of Python on your computer. If you do not do anything, Jupyter lab will run the default version of Python. Let’s say there is a new version of Python and you install it, making it the default one. If you need to run a different, older, version of Python in Jupyter Lab, you can do write the code that you see in the next image.

 

To use a specific version of Python in Jupyter Lab
To use a specific version of Python in Jupyter Lab

On my computer, for example, I have the version 3.6 (as default version) and also the new 3.7 version. Here is an example of use of the new dataclassee in Python 3.7, that I can’t use in versio 3.6.

%%script C:\Users\Utente\AppDAta\Local\Programs\Python\Python37\python.exe

from dataclasses import dataclass

@dataclass
class Data:
	name: str
	age: int
	def printData(self):
		print(f'I am {self.name}')
		print(f'My age is {self.age}')

a1 = Data("John", 35)
a1.printData()

 

Python 3.7, dataclasses, use this version in Jupyter Lab.
Python 3.7, dataclasses, use this version in Jupyter Lab.

Video

Here is the video that shows you how to start different version of Python in Jupyter lab.

%

New features in Python 3.6

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.