如何在单个 Conda 环境中安装两个版本的 Python?
How can I install two versions of Python on a single Conda Environment?
我需要一个带有 两个版本 python(3.5.3 和 3.7.1)的 conda 环境。
是否可以在单个 conda 环境中安装多个 python 版本?
如果是,我该怎么做?
请花时间阅读the Conda documentation, which covers 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
我需要一个带有 两个版本 python(3.5.3 和 3.7.1)的 conda 环境。
是否可以在单个 conda 环境中安装多个 python 版本? 如果是,我该怎么做?
请花时间阅读the Conda documentation, which covers 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