如何从 notebook 中找到 jupyter notebook 的版本

Cre*_*eek 5 python jupyter-notebook jupyter-lab

我希望从笔记本的单元格中返回 Jupyter Notebook 的版本。

例如,要获取 python 版本,我运行:

from platform import python_version
python_version()
Run Code Online (Sandbox Code Playgroud)

或获取熊猫版本:

pd.__version__
Run Code Online (Sandbox Code Playgroud)

我试过了:

notebook.version()
ipython.version()
jupyter.version()
Run Code Online (Sandbox Code Playgroud)

以及其他几个相关的表格(包括首字母大写),但出现以下错误(例如):

NameError:未定义名称“jupyter”

我知道其他方法(例如,在 GUI 菜单中单击“帮助”>“关于”;使用 conda 命令行)但我想自动化所有包版本的文档。

如果重要的话,我在 Python 3.7.3 环境中运行 Notebook v6.1.1。

n0n*_*vme 8

将以下命令粘贴到您的 jupyter 单元格中(感叹号表示您需要运行 shell 命令,而不是 python)

!jupyter --version
Run Code Online (Sandbox Code Playgroud)

示例输出:

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
Run Code Online (Sandbox Code Playgroud)

要获取 python 版本,请使用以下python --version命令:

!python --version
Run Code Online (Sandbox Code Playgroud)

示例输出:

Python 3.6.8
Run Code Online (Sandbox Code Playgroud)

更新: 要将值作为 dict 获取,您可以使用以下脚本(不完美,3 分钟内编写)

!jupyter --version
Run Code Online (Sandbox Code Playgroud)

价值parsed_versions变量

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
Run Code Online (Sandbox Code Playgroud)

更新 2:感谢@TrentonMcKinney 提供有关如何改进此脚本的建议

  • 杰出的!正是我要找的。为你和特伦顿干杯。 (2认同)