Create Environments with Different Python Versions in Anaconda

Raymond Tang Raymond Tang 0 6502 5.10 index 12/30/2021

With Anaconda, we can create virtual environments with different Python versions. This can be very handy when certain package only supports certain Python versions.

This article shows you the simple guide of creating different environments.

Install Anaconda

You can install the individual edition from this website: https://www.anaconda.com/products/individual.

2021123005004-image.png

Once installed, open CMD.exe Prompt from the navigator.

Create virtual environments

The following commands create three environments with different Python versions:

conda create -n py37 python=3.7conda create -n py38 python=3.8conda create -n py39 python=3.9

The above command lines create three environments named py37, py38 and py39 with python versions 3.7, 3.8 and 3.9 respectively.

Activate environments

You can use conda activate $environment_name to activate environments.

conda activate py37

The above command line activate virtual environment named py37.

Deactivate environments

To deactivate, simply run the following command and Anaconda Prompt will switch back to the default environment:

conda deactivate

Install packages

Install package using the following command line:

conda install package_name

You can also install pipin the environment and then use pipto install packages.

python

Join the Discussion

View or add your thoughts below

Comments