【问题标题】:How can I install two versions of Python on a single Conda Environment?如何在单个 Conda 环境中安装两个版本的 Python?
【发布时间】:2021-08-08 05:05:37
【问题描述】:

我需要一个带有两个版本的 python(3.5.3 和 3.7.1)的 conda 环境。

是否可以在单个 conda 环境中安装多个 python 版本? 如果是,我该怎么做?

【问题讨论】:

  • 如果没有明确的重复建议,我会感到惊讶,但经过短暂搜索后我找不到。如果有人找到了,请联系我,我会加入一份简历。
  • 谢谢 Grismar 和 merv,这正是我想的两个,如果我错过了什么,我只是感到困惑。好吧,我将尝试使用两个 venv,每个都带有一个 python 版本,我会看看这是否能解决我的问题。

标签: python anaconda conda python-venv miniconda


【解决方案1】:

请花点时间阅读the Conda documentation,其中涵盖了using different Python versions

不能在同一环境中安装不同的 Python 版本。正如@Grismar 评论的那样,将不同的 Python 安装相互隔离是环境的中心目的。相反,为每个 Python 版本(或者更好的是,为每个项目)创建一个单独的环境:

# v3.5.3 environment (name is arbitrary)
conda create -n python3_5_3 python=3.5.3  # also include additional packages here

# v3.7.1 env
conda create -n python3_7_1 python=3.7.1

然后激活使用选择的环境:

conda activate python3_7_1
python

使用 Conda 和 Mamba 进行测试

在我看来,仅仅尝试使用 Conda 安装两者并不会给出明显的错误:

$ conda create -n snakes python=3.5.3 python=3.7.1
Collecting package metadata (current_repodata.json): done
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed

PackagesNotFoundError: The following packages are not available from current channels:

  - python[version='3.5.3.*,3.7.1.*']

但是,Mamba 似乎提供了更明智的反馈(而且速度更快):

$ mamba create -n snakes python=3.5.3 python=3.7.1

                  __    __    __    __
                 /  \  /  \  /  \  /  \
                /    \/    \/    \/    \
███████████████/  /██/  /██/  /██/  /████████████████████████
              /  / \   / \   / \   / \  \____
             /  /   \_/   \_/   \_/   \    o \__,
            / _/                       \_____/  `
            |/
        ███╗   ███╗ █████╗ ███╗   ███╗██████╗  █████╗
        ████╗ ████║██╔══██╗████╗ ████║██╔══██╗██╔══██╗
        ██╔████╔██║███████║██╔████╔██║██████╔╝███████║
        ██║╚██╔╝██║██╔══██║██║╚██╔╝██║██╔══██╗██╔══██║
        ██║ ╚═╝ ██║██║  ██║██║ ╚═╝ ██║██████╔╝██║  ██║
        ╚═╝     ╚═╝╚═╝  ╚═╝╚═╝     ╚═╝╚═════╝ ╚═╝  ╚═╝

        mamba (0.11.1) supported by @QuantStack

        GitHub:  https://github.com/mamba-org/mamba
        Twitter: https://twitter.com/QuantStack

█████████████████████████████████████████████████████████████


Looking for: ['python=3.5.3', 'python=3.7.1']

conda-forge/osx-64       Using cache
conda-forge/noarch       Using cache
pkgs/main/osx-64         Using cache
pkgs/main/noarch         Using cache
pkgs/r/osx-64            Using cache
pkgs/r/noarch            Using cache

Encountered problems while solving:
  - cannot install both python-3.7.1-h145921a_1000 and python-3.5.3-0

【讨论】:

  • 我猜想,OP 的原因是他们应用程序中的两个包依赖于不同版本的 Python。这就是为什么他们需要在同一个环境中安装多个版本的 Python
猜你喜欢
  • 1970-01-01
  • 2020-11-06
  • 2014-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-14
  • 1970-01-01
  • 2023-02-07
相关资源
最近更新 更多