Bash命令:列出所有Conda环境的Python版本

要列出所有Conda环境的Python版本,您可以在Bash终端中使用以下命令:

conda info --envs | \
awk '{print $1}' | \
xargs -I {} sh -c 'echo {}; conda run -n {} python --version 2>&1 | cut -d " " -f 2'

该命令首先使用 conda info --envs 列出所有Conda环境,然后将输出传输到 awk 以提取第一列,其中包含环境名称。使用 xargs 将每个环境名称传递给一个shell命令,该命令在该环境中运行 python --version。最后,使用 cut 从 python --version 的输出中提取Python版本号。

该命令将输出所有Conda环境名称,后跟每个环境的Python版本号。

注: 如果包含非CPython实现, 例如PyPy, 请移除cut命令, 即:

conda info --envs | \
awk '{print $1}' | \
xargs -I {} sh -c 'echo {}; conda run -n {} python --version 2>&1'

你可能感兴趣的:(python,bash,conda)