把以下命令粘贴到你的jupyter单元格中(惊叹号表示你需要运行shell命令,而不是Python)。
把以下命令粘贴到你的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 --version
命令获取 Python 版本:
!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提供了有关如何改进此脚本的建议。