8

I wish to return the version of Jupyter Notebook from within a cell of a notebook.

For example, to get the python version, I run:

from platform import python_version
python_version()

or to get the pandas version:

pd.__version__

I have tried:

notebook.version()
ipython.version()
jupyter.version()

and several other, related forms (including capitalizing the first letters), but get errors that (for example):

NameError: name 'jupyter' is not defined

I am aware of other ways (e.g. clicking on Help>About in the GUI menu; using the conda command line) but I want to automate documentation of all package versions.

If it matters, I am running v6.1.1 of Notebook in a Python 3.7.3 environment.

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
CreekGeek
  • 1,809
  • 2
  • 14
  • 24

2 Answers2

17

Paste the following command into your jupyter cell(exclamation symbol means that you need to run shell command, not python)

!jupyter --version

example output:

jupyter core     : 4.6.0
jupyter-notebook : 6.0.1
qtconsole        : 4.7.5
ipython          : 7.8.0
ipykernel        : 5.1.3
jupyter client   : 5.3.4
jupyter lab      : not installed
nbconvert        : 5.6.0
ipywidgets       : 7.5.1
nbformat         : 4.4.0
traitlets        : 4.3.3

To get the python version use the python --version command:

!python --version

example output:

Python 3.6.8

UPDATE: to get values as dict you can use the following script(not perfect, written in 3 minutes)

import subprocess
versions = subprocess.check_output(["jupyter", "--version"]).decode().split('\n')
parsed_versions = {}
for component in versions:
    if component == "":
        continue
    comps = list(map(str.strip, component.split(': ')))
    parsed_versions[comps[0]] = comps[1]

Value of parsed_versions variable

{
    "jupyter core": "4.6.0",
    "jupyter-notebook": "6.0.1",
    "qtconsole": "4.7.5",
    "ipython": "7.8.0",
    "ipykernel": "5.1.3",
    "jupyter client": "5.3.4",
    "jupyter lab": "not installed",
    "nbconvert": "5.6.0",
    "ipywidgets": "7.5.1",
    "nbformat": "4.4.0",
    "traitlets": "4.3.3"
}

UPDATE 2: Thanks to @TrentonMcKinney for suggestions on how to make this script better

n0nvme
  • 1,248
  • 8
  • 18
2

if you only need to know jupyter lab version from python code, this should work :

import jupyterlab
print(jupyterlab.__version__)
Selmen
  • 21
  • 5