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

标签 python jupyter-notebook jupyter-lab

我希望从笔记本的单元格中返回 Jupyter Notebook 的版本。
例如,要获取 python 版本,我运行:

from platform import python_version
python_version()
或获取 Pandas 版本:
pd.__version__
我试过了:
notebook.version()
ipython.version()
jupyter.version()
以及其他几个相关的表格(包括首字母大写),但出现以下错误(例如):

NameError: name 'jupyter' is not defined


我知道其他方法(例如,在 GUI 菜单中单击“帮助”>“关于”;使用 conda 命令行),但我想自动化所有包版本的文档。
如果重要的话,我正在 Python 3.7.3 环境中运行 Notebook v6.1.1。

最佳答案

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

!jupyter --version
示例输出:
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
要获取 python 版本,请使用 python --version命令:
!python --version
示例输出:
Python 3.6.8
更新:
要将值作为字典,您可以使用以下脚本(不完美,在 3 分钟内编写)
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]
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"
}
更新 2:感谢@TrentonMcKinney 提供有关如何改进此脚本的建议

关于python - 如何从 notebook 中找到 jupyter notebook 的版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64323745/

相关文章:

matplotlib - 在python中将矩阵绘制为表格

python - 重新连接远程 Jupyter Notebook 并获取当前单元格输出

Python 覆盖窗口

python记录器多次记录相同的条目

python - "return +/- "在 python 中做什么?

python - Jupyter 中的内联动画

python - 使用 for 循环创建一定数量的输入框,但只能从最后一个输入框获取最后一个值

kubernetes - kubernetes 中的有状态 jupyter 笔记本

python - 建议使用 JupyterLab 构建并成功安装,但无法工作。为什么?

python - 如何在 matplotlib 中添加标记样式列表?