How can I install two versions of Python on a single Conda Environment?

Viewed 3237

I need to have a conda environment with two versions of python (3.5.3 and 3.7.1).

Is it possible to have multiple python versions installed in a single conda environment? And if yes, how can I do so?

2 Answers

Please take time to read the Conda documentation, which covers using different Python versions.

One cannot install different Python versions in the same environment. As @Grismar commented, it is a central purpose of environments to isolate different Python installations from each other. Instead, create a separate environment for each Python version (or, better, for each project):

# 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

Then activate to use the environment of choice:

conda activate python3_7_1
python

Testing with Conda and Mamba

Simply trying to install both with Conda doesn't give a clear error, in my opinion:

$ 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.*']

However, Mamba seems to give more sensible feedback (and much faster):

$ 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

I have two different versions in same environment [1]: https://i.stack.imgur.com/ZMU8k.png

I have two versions of python in one environment. when i enter python it gives me python version 3.8.0 and when i enter python3 it gives me python version 3.9.1

Related