如何在单个 Conda 环境中安装两个版本的 Python?

时间:2021-05-18 23:11:50

标签: python anaconda conda python-venv miniconda

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

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

1 个答案:

答案 0 :(得分:2)

请花点时间阅读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
相关问题