在 Google Colab 中运行时 conda 环境中实际的 Python 版本?

问题描述 投票:0回答:1

我在 Google Colab 中运行笔记本,并在那里安装 miniconda 并为应用程序创建适当的环境。能够读出环境中实际拥有的 Python 版本是件好事。

例如:

调用 platform.python_version() 给出 3.10.12

调用 !Python --version 给出 3.12.2

调用 !conda list python 也给出 3.12.2

在我看来,platform.python_version() 指的是我不知道的其他一些Python 安装。在这个例子中,!conda list 给出的可能是本地环境的相关信息,对吗?

这个其他 Python 安装到底是什么?

python jupyter-notebook google-colaboratory miniconda
1个回答
0
投票

因此,笔记本是使用 python 内核运行的。并且该内核可能与 bash/zsh 终端中的默认内核不同。

当您运行此代码片段时,您将获得笔记本内部使用的 python 版本。

platform.python_version()

相比之下,当你运行时,你会得到 bash/zsh 终端中使用的 env。

!Python --version gives 3.12.2
!conda list python gives also 3.12.2

这很可能意味着您的 3.12.2 环境没有安装

jupyter lab
,因此命令
jupyter
指向其他环境。

另外,作为解决方案,我建议在实验室笔记本中创建新的 python 内核,并在内核路径中指定您想要在开发过程中使用的 python 路径。

© www.soinside.com 2019 - 2024. All rights reserved.