How to find the version of jupyter notebook from within the notebook

2024/10/15 21:18:03

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.

Answer

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 == "":continuecomps = 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

https://en.xdnf.cn/q/69234.html

Related Q&A

Python logging - multiple modules

Im working on a small python project that has the following structure -project -- logs-- project__init.py__classA.pyclassB.pyutils.py-- main.pyIve set up the logging configuration in __init.py__ under …

Can you search backwards from an offset using a Python regular expression?

Given a string, and a character offset within that string, can I search backwards using a Python regular expression?The actual problem Im trying to solve is to get a matching phrase at a particular of…

Django AttributeError: Form object has no attribute _errors

Im overriding the init method in my form andthis is now returning an error TransactionForm object has no attribute _errors. I would expect this to work because Ive included super in my init, however pe…

Add new keys to a dictionary while incrementing existing values

I am processing a CSV file and counting the unique values of column 4. So far I have coded this three ways. One uses "if key in dictionary", the second traps the KeyError and the third uses &…

ImportError: cannot import name aiplatform from google.cloud (unknown location)

I was wondering where that error comes from. The package has to be installed additionally to google.cloud

What does : TypeError: cannot concatenate str and list objects mean?

What does this error mean?TypeError: cannot concatenate str and list objectsHeres part of the code:for j in (90.,52.62263.,26.5651.,10.8123.):if j == 90.:z = (0.)elif j == 52.62263.:z = (0., 72., 144.…

How do I create a fixed-length, mutable array of Python objects in Cython?

I need to have an array of python objects to be used in creating a trie datastructure. I need a structure that will be fixed-length like a tuple and mutable like a list. I dont want to use a list bec…

How to install atari-py in Windows 10? [duplicate]

This question already has answers here:OpenAI Gym Atari on Windows(5 answers)Closed 3 years ago.I tried to install lib pack atari-py, and can not find any clear information, most of them wrote that it …

Using pyplot to create grids of plots

I am new to python and having some difficulties with plotting using pyplot. My goal is to plot a grid of plots in-line (%pylab inline) in Juypter Notebook.I programmed a function plot_CV which plots cr…

matplotlib: deliberately block code execution pending a GUI event

Is there some way that I can get matplotlib to block code execution pending a matplotlib.backend_bases.Event?Ive been working on some classes for interactively drawing lines and polygons inside matplo…