conda

conda#

Find a conda cheatsheet

To install conda, please go here.

conda – environment#

The conda Python package automatically incorporates environments. Not only will it allow environments with specific packages, one can also create environments with different Python versions. This can be useful if a specific package requires a specific Python version.

Once an environment has been created, and sourced, all python commands only act in that environment.

An environment can be created using:

Note

One can list the available global environments (created with --name) by executing conda env list.

conda create --name <name of env>
# create an environment named 'course-A' (in the global environment list)
conda create --name course-A
# alternatively the environment can be placed in a sub directory
conda create --prefix course-A
conda create --name <name of env>
# create an environment named 'course-A' (in the global environment list)
conda create --name course-A
 # alternatively the environment can be placed in a sub directory
conda create --prefix course-A
conda create --name <name of env>
# create an environment named 'course-A' (in the global environment list)
conda create --name course-A
# alternatively the environment can be placed in a sub directory
conda create --prefix course-A
conda create --name <name of env>
# create an environment named 'course-A' (in the global environment list)
conda create --name course-A
# alternatively the environment can be placed in a sub directory
conda create --prefix course-A

Once created, one can use the environment by activating it. Change course-A with the name of the environment.

# if the enviroment was created with --name:
conda activate course-A
# if the environment was created in a sub directory (--prefix):
conda activate .\course-A
# if the enviroment was created with --name:
conda activate course-A
# if the environment was created in a sub directory (--prefix):
conda activate .\course-A
# if the enviroment was created with --name:
conda activate course-A
# if the environment was created in a sub directory (--prefix):
conda activate ./course-A
# if the enviroment was created with --name:
conda activate course-A
# if the environment was created in a sub directory (--prefix):
conda activate ./course-A

Now every executed Python script will only use the packages installed in the environment. Every conda install will only install/remove packages in the environment. To get out of the environment, simply run the command conda deactivate.

Below is a complete example of creating an environment using a specific Python version, installing a specific package, running a code using the environment, and getting out of it.

conda create --name numpy-env python=3.10
conda activate numpy-env
conda install "numpy=1.23"
python -c "import numpy as np ; print(np.__version__)"
conda deactivate
conda create --name numpy-env python=3.10
conda activate numpy-env
conda install "numpy=1.23"
python -c "import numpy as np ; print(np.__version__)"
conda deactivate
conda create --name numpy-env python=3.10
conda activate numpy-env
conda install "numpy=1.23"
python3 -c "import numpy as np ; print(np.__version__)"
conda deactivate
conda create --name numpy-env python=3.10
conda activate numpy-env
conda install "numpy=1.23"
python3 -c "import numpy as np ; print(np.__version__)"
conda deactivate