Reproducible computational environments with Conda
30 October 2024
Command Line Interface
command + Space
and search
Terminal
anaconda
and select Anaconda Prompt or
Anaconda Powershell PromptA directory that contains specific installed packages (system libraries, python/R modules, …).
The default environment that you have when installing conda.
. . .
Which version of conda are you running?
Inspect the output of conda info
especially:
platform, Python version, active environment, base environment and
channel URLs.
$ conda create --name py38 python=3.8
$ conda create --name py38-clone --clone py38
$ conda env list
--name py38
- py38 is the name of
the environmentpython=3.8
- python package version
3.8 is installed in the new environment--clone py38
- py38 is the name of
the cloned existing environmentconda env list
- is equivalent with
conda info --env
Check Python version on:
$ python --version
$ conda activate
(base)$ python --version
(base)$ conda activate py38
(py38)$ python --version
(py38)$ conda deactivate --help
(py38)$ conda deactivate
conda activate
- the default (base)
environment is activatedconda activate py38
- py38 is the
name of the environment $ conda activate py38
(py38)$ conda list
(py38)$ conda list --name base
(py38)$ conda list python
(py38)$ conda list --name base python
list --name base
- base is the name
of the environmentlist python
- only packages matching
python string (regular expression) in the active
environment (or base if no one active)Locations where packages are stored, e.g. default / main, conda-forge, bioconda, r
(py38)$ conda deactivate && conda deactivate
$ conda search numpy=1.21
$ conda install numpy=1.21.6 --name py38
$ conda activate py38
(py38)$ conda install pandas="<1.5"
install pandas="<1.5"
- the quotes are
mandatory(py38)$ conda update pandas
(py38)$ conda update --all
(py38)$ conda list --revisions
(py38)$ conda install --revision 2
(py38)$ conda list --revisions
update ... pandas
- update pandas
to the latest compatible versionupdate --all
- update all packageslist --revisions
- list history of changesinstall --revision 2
- restore to revision
2Note: In restoring to a revision the additional channels are needed explicitly.
A YAML file that contains all information to create an environment.
YAML file: seaborn.yml
Note: seaborn
is is a
Python data visualization library based on matplotlib
.
(py38)$ conda env create --file seaborn.yml
(py38)$ conda activate seaborn
(seaborn)$ conda env export
(seaborn)$ conda env export --no-builds
(seaborn)$ conda env export --from-history
(seaborn)$ conda env export --no-builds > seaborn_export.yaml
(seaborn)$ conda env create --file seaborn_export.yaml --name seaborn_export
env export
- all installed packages are exported (in
yaml format)env export --no-builds
- the build specification is
removedenv export --from-history
- all packages that you
explicitly asked forNote: The build specification is generally platform dependent.
Note: The packages might not be available on all platforms.
A text file that contains all information to create an identical environment.
(seaborn)$ conda list --explicit
(seaborn)$ conda list --explicit > seaborn_spec_file.txt
(seaborn)$ conda create --name seaborn_explicit --file seaborn_spec_file.txt
conda create --file seaborn_spec_file.txt
- conda
does not check the platform nor the dependenciesWarning: Use the spec file on a similar platform.
Finally, try yourself to remove some or all of the environments that we just created.
Hint: Have a look at the documentation for the
conda env
command: conda env --help
Note: You cannot remove the active environment!