Environment Management with Conda
Authors
Most software we use comes with a list of dependencies which, in turn, have their own dependencies. This means that any given piece of software requires a specific environment of other packages to function properly. The larger the tree of dependencies, the more likely it is that two pieces of software have a version conflict because they require different versions of the same dependency. This can be prevented by using virtual environments. Virtual environments are self-contained boxes that are used only within a specific narrow scope. By creating a dedicated virtual environment for every project we can isolate the software and avoid conflicts. We can also improve the reproducibility of our research because the virtual environment can be shared together with the code and data.
In this notebook, you are going to learn how to use Conda - an established and widely used tool for creating and managing virtual environments. Conda allows us to create new virtual environments, either directly in the project folder or system wide, install packages and run code in them. Conda can also export the current environment to a environment.yml file which can be used to reproduce the computational environment.
Setup
The exercises in this notebook assume that you have installed Conda from Miniforge and Visual Studio Code. If you haven’t, just click on the link and follow the instructions for your operating system on the website. To test if Conda was installed correctly, open a terminal (in VSCode select View>Terminal from the menu bar or press Ctrl+`) and type conda --version. If you are getting an error saying that the command was not found, try restarting VSCode.
conda --versionconda 24.11.3Section 1: Creating and Managing Environments
Background
One of the key advantages of Conda is its ability to create isolated environments, which are essentially self-contained workspaces with their own packages and dependencies. This allows you to experiment, develop, and analyze data without worrying about conflicts between different package versions, which can often disrupt workflows. This is especially helpful for reproducible research: by keeping dependencies organized, you ensure that your projects are replicable across systems.
When creating a new Conda environment, you give it a name using the -n flag and Conda will store it in a new subfolder in the directory where Conda is installed which defaults to C:\Users\<username>\miniforge3 on Windows and ~/miniforge3 on Linux/MacOS.
For example, a new environment called new_env will be stored in miniforge3/new_env.
To activate an environment, type conda activate <environment name> and Conda will look in the installation directory for an environment that matches the name.
Exercises
In the following exercises, you will learn how to create new environments, activate and deactivate them and get a list of your existing environments. Here are the different commands required to solve the exercises:
| Code | Description |
|---|---|
conda create -n env_name |
Create a new environment named env_name |
conda env list |
List all existing Conda environments |
conda activate env_name |
Activate the environment env_name |
conda deactivate |
Deactivate the current Conda environment |
ls folder/subfolder |
List the content of folder/subfolder |
Exercise: Create a new Conda environment with the name (-n) test_env and confirm the action by typing y.
Solution
conda create -n test_env
Retrieving notices: done
Channels:
- conda-forge
Platform: linux-64
Collecting package metadata (repodata.json): done
Solving environment: done
## Package Plan ##
environment location: /home/olebi/miniforge3/envs/test_env
Proceed ([y]/n)? y
Downloading and Extracting Packages:
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate test_env
#
# To deactivate an active environment, use
#
# $ conda deactivateExercise: List all environments to verify that test_env was created.
Solution
conda env list
# conda environments:
#
test_env /home/olebi/miniforge3/envs/test_envExercise: Activate test_env. You should see (test_env) appear on the left of your terminal’s input line.
Solution
conda activate test_envExercise: Deactivate test_env again.
Solution
conda deactivateExercise: Create a new Conda environment with the name (-n) test_env2 and confirm the action by typing y.
Solution
conda create -n test_env2
Channels:
- conda-forge
Platform: linux-64
Collecting package metadata (repodata.json): done
Solving environment: done
## Package Plan ##
environment location: /home/olebi/miniforge3/envs/test_env2
Proceed ([y]/n)? y
Downloading and Extracting Packages:
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate test_env2
#
# To deactivate an active environment, use
#
# $ conda deactivateExercise: List all environments and note the path where test_env2 is stored.
Solution
conda env list
# conda environments:
#
test_env /home/olebi/miniforge3/envs/test_env
test_env2 /home/olebi/miniforge3/envs/test_env2Exercise: View the content of the test_env2/ folder, either by moving to that directory using your file explorer or by using the ls command.
Solution
ls /home/olebi/miniforge3/envs/test_env2 # change the path to reflect the location on your machineconda-metaExercise: Activate test_env2, then deactivate it again.
Solution
conda activate test_env2
conda deactivateSection 2: Installing Packages in Environments
Background
Managing packages within Conda environments allows you to install libraries and dependencies specific to each project. This helps avoid the challenges of “dependency hell” where incompatible package versions interfere with each other. For researchers, Conda’s ability to install non-Python packages (like r-base or system libraries) provides flexibility and power, especially for complex data workflows involving multiple languages.
When running conda install <package name>, Conda will look through the conda-forge repository for a package with a matching name, download and install it. If no package with that name can be found, you’ll get an error.
The conda-forge repository contains a wealth of scientific packages for download. You can view a full list here: https://conda-forge.org/packages/ To install a package into a specific environment, you can either activate the environment or use the -n flag to specify the name of the environment where the package should be installed.
Exercises
In the following exercises, you are going to create new environments to install interpreters for the programming languages Python and R. Here are the commands you need to know:
| Code | Description |
|---|---|
conda install package_name |
Install package_name in the active environment |
conda install -n env_name package_name |
Install package_name into env_name |
conda list |
List all installed packages in the active environment |
Exercise: Create new environment named py_env and activate it.
Solution
conda create -n py_env
conda activate py_env
Channels:
- conda-forge
Platform: linux-64
Collecting package metadata (repodata.json): done
Solving environment: done
## Package Plan ##
environment location: /home/olebi/miniforge3/envs/py_env
Proceed ([y]/n)? y
Downloading and Extracting Packages:
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate py_env
#
# To deactivate an active environment, use
#
# $ conda deactivateExercise: Install python=3.12 in py_env and confirm the installation by entering y.
Solution
conda install python=3.12
Channels:
- conda-forge
Platform: linux-64
Collecting package metadata (repodata.json): done
Solving environment: done
## Package Plan ##
environment location: /home/olebi/miniforge3/envs/py_env
added / updated specs:
- python=3.12
The following packages will be downloaded:
package | build
---------------------------|-----------------
icu-78.1 | h33c6efd_0 12.1 MB conda-forge
ld_impl_linux-64-2.45 |default_hbd61a6d_105 714 KB conda-forge
libgcc-15.2.0 | he0feb66_16 1018 KB conda-forge
libgcc-ng-15.2.0 | h69a702a_16 27 KB conda-forge
libgomp-15.2.0 | he0feb66_16 589 KB conda-forge
libsqlite-3.51.1 | hf4e2dac_1 921 KB conda-forge
libstdcxx-15.2.0 | h934c35e_16 5.6 MB conda-forge
libuuid-2.41.3 | h5347b49_0 39 KB conda-forge
pip-25.3 | pyh8b19718_0 1.1 MB conda-forge
python-3.12.12 |hd63d673_1_cpython 30.1 MB conda-forge
readline-8.3 | h853b02a_0 337 KB conda-forge
tk-8.6.13 |noxft_ha0e22de_103 3.1 MB conda-forge
tzdata-2025c | hc9c84f9_1 116 KB conda-forge
zstd-1.5.7 | hb78ec9c_6 587 KB conda-forge
------------------------------------------------------------
Total: 56.3 MB
The following NEW packages will be INSTALLED:
_libgcc_mutex conda-forge/linux-64::_libgcc_mutex-0.1-conda_forge
_openmp_mutex conda-forge/linux-64::_openmp_mutex-4.5-2_gnu
bzip2 conda-forge/linux-64::bzip2-1.0.8-hda65f42_8
ca-certificates conda-forge/noarch::ca-certificates-2026.1.4-hbd8a1cb_0
icu conda-forge/linux-64::icu-78.1-h33c6efd_0
ld_impl_linux-64 conda-forge/linux-64::ld_impl_linux-64-2.45-default_hbd61a6d_105
libexpat conda-forge/linux-64::libexpat-2.7.3-hecca717_0
libffi conda-forge/linux-64::libffi-3.5.2-h9ec8514_0
libgcc conda-forge/linux-64::libgcc-15.2.0-he0feb66_16
libgcc-ng conda-forge/linux-64::libgcc-ng-15.2.0-h69a702a_16
libgomp conda-forge/linux-64::libgomp-15.2.0-he0feb66_16
liblzma conda-forge/linux-64::liblzma-5.8.1-hb9d3cd8_2
libnsl conda-forge/linux-64::libnsl-2.0.1-hb9d3cd8_1
libsqlite conda-forge/linux-64::libsqlite-3.51.1-hf4e2dac_1
libstdcxx conda-forge/linux-64::libstdcxx-15.2.0-h934c35e_16
libuuid conda-forge/linux-64::libuuid-2.41.3-h5347b49_0
libxcrypt conda-forge/linux-64::libxcrypt-4.4.36-hd590300_1
libzlib conda-forge/linux-64::libzlib-1.3.1-hb9d3cd8_2
ncurses conda-forge/linux-64::ncurses-6.5-h2d0b736_3
openssl conda-forge/linux-64::openssl-3.6.0-h26f9b46_0
pip conda-forge/noarch::pip-25.3-pyh8b19718_0
python conda-forge/linux-64::python-3.12.12-hd63d673_1_cpython
readline conda-forge/linux-64::readline-8.3-h853b02a_0
setuptools conda-forge/noarch::setuptools-80.9.0-pyhff2d567_0
tk conda-forge/linux-64::tk-8.6.13-noxft_ha0e22de_103
tzdata conda-forge/noarch::tzdata-2025c-hc9c84f9_1
wheel conda-forge/noarch::wheel-0.45.1-pyhd8ed1ab_1
zstd conda-forge/linux-64::zstd-1.5.7-hb78ec9c_6
Proceed ([y]/n)? y
Downloading and Extracting Packages:
Preparing transaction: done
Verifying transaction: done
Executing transaction: done Exercise: Install the numpy package in py_env.
Solution
conda install numpy
Channels:
- conda-forge
Platform: linux-64
Collecting package metadata (repodata.json): done
Solving environment: done
## Package Plan ##
environment location: /home/olebi/miniforge3/envs/py_env
added / updated specs:
- numpy
The following packages will be downloaded:
package | build
---------------------------|-----------------
numpy-2.4.0 | py312h33ff503_0 8.3 MB conda-forge
python_abi-3.12 | 8_cp312 7 KB conda-forge
------------------------------------------------------------
Total: 8.4 MB
The following NEW packages will be INSTALLED:
libblas conda-forge/linux-64::libblas-3.11.0-5_h4a7cf45_openblas
libcblas conda-forge/linux-64::libcblas-3.11.0-5_h0358290_openblas
libgfortran conda-forge/linux-64::libgfortran-15.2.0-h69a702a_16
libgfortran5 conda-forge/linux-64::libgfortran5-15.2.0-h68bc16d_16
liblapack conda-forge/linux-64::liblapack-3.11.0-5_h47877c9_openblas
libopenblas conda-forge/linux-64::libopenblas-0.3.30-pthreads_h94d23a6_4
numpy conda-forge/linux-64::numpy-2.4.0-py312h33ff503_0
python_abi conda-forge/noarch::python_abi-3.12-8_cp312
Proceed ([y]/n)? y
Downloading and Extracting Packages:
Preparing transaction: done
Verifying transaction: done
Executing transaction: doneExercises: List all installed packages to verify that Python 3.12 and Numpy were installed.
Solution
conda list
# packages in environment at /home/olebi/miniforge3/envs/py_env:
#
# Name Version Build Channel
_libgcc_mutex 0.1 conda_forge conda-forge
_openmp_mutex 4.5 2_gnu conda-forge
bzip2 1.0.8 hda65f42_8 conda-forge
ca-certificates 2026.1.4 hbd8a1cb_0 conda-forge
icu 78.1 h33c6efd_0 conda-forge
ld_impl_linux-64 2.45 default_hbd61a6d_105 conda-forge
libblas 3.11.0 5_h4a7cf45_openblas conda-forge
libcblas 3.11.0 5_h0358290_openblas conda-forge
libexpat 2.7.3 hecca717_0 conda-forge
libffi 3.5.2 h9ec8514_0 conda-forge
libgcc 15.2.0 he0feb66_16 conda-forge
libgcc-ng 15.2.0 h69a702a_16 conda-forge
libgfortran 15.2.0 h69a702a_16 conda-forge
libgfortran5 15.2.0 h68bc16d_16 conda-forge
libgomp 15.2.0 he0feb66_16 conda-forge
liblapack 3.11.0 5_h47877c9_openblas conda-forge
liblzma 5.8.1 hb9d3cd8_2 conda-forge
libnsl 2.0.1 hb9d3cd8_1 conda-forge
libopenblas 0.3.30 pthreads_h94d23a6_4 conda-forge
libsqlite 3.51.1 hf4e2dac_1 conda-forge
libstdcxx 15.2.0 h934c35e_16 conda-forge
libuuid 2.41.3 h5347b49_0 conda-forge
libxcrypt 4.4.36 hd590300_1 conda-forge
libzlib 1.3.1 hb9d3cd8_2 conda-forge
ncurses 6.5 h2d0b736_3 conda-forge
numpy 2.4.0 py312h33ff503_0 conda-forge
openssl 3.6.0 h26f9b46_0 conda-forge
pip 25.3 pyh8b19718_0 conda-forge
python 3.12.12 hd63d673_1_cpython conda-forge
python_abi 3.12 8_cp312 conda-forge
readline 8.3 h853b02a_0 conda-forge
setuptools 80.9.0 pyhff2d567_0 conda-forge
tk 8.6.13 noxft_ha0e22de_103 conda-forge
tzdata 2025c hc9c84f9_1 conda-forge
wheel 0.45.1 pyhd8ed1ab_1 conda-forge
zstd 1.5.7 hb78ec9c_6 conda-forgeExercise: Create new environment named r_env and activate it.
Solution
conda create -n r_env
conda activate r_env
Channels:
- conda-forge
Platform: linux-64
Collecting package metadata (repodata.json): done
Solving environment: done
## Package Plan ##
environment location: /home/olebi/miniforge3/envs/r_env
Proceed ([y]/n)? y
Downloading and Extracting Packages:
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate r_env
#
# To deactivate an active environment, use
#
# $ conda deactivateExercise: Install r-base into r_env, then list all packages to confirm that the installation was successful.
Solution
conda install r-base
conda list
Channels:
- conda-forge
Platform: linux-64
Collecting package metadata (repodata.json): done
Solving environment: done
## Package Plan ##
environment location: /home/olebi/miniforge3/envs/r_env
added / updated specs:
- r-base
The following packages will be downloaded:
package | build
---------------------------|-----------------
binutils_impl_linux-64-2.45|default_hfdba357_105 3.5 MB conda-forge
c-ares-1.34.6 | hb03c661_0 203 KB conda-forge
curl-8.17.0 | h4e3cde8_1 183 KB conda-forge
gcc_impl_linux-64-15.2.0 | hc5723f1_16 76.6 MB conda-forge
gfortran_impl_linux-64-15.2.0| h281d09f_16 19.1 MB conda-forge
gxx_impl_linux-64-15.2.0 | hda75c37_16 15.6 MB conda-forge
kernel-headers_linux-64-6.12.0| he073ed8_5 1.5 MB conda-forge
libblas-3.11.0 |5_h4a7cf45_openblas 18 KB conda-forge
libcblas-3.11.0 |5_h0358290_openblas 18 KB conda-forge
libcurl-8.17.0 | h4e3cde8_1 449 KB conda-forge
libdeflate-1.25 | h17f619e_0 72 KB conda-forge
libgcc-devel_linux-64-15.2.0| hcc6f6b0_116 3.0 MB conda-forge
libgfortran-15.2.0 | h69a702a_16 27 KB conda-forge
libgfortran-ng-15.2.0 | h69a702a_16 27 KB conda-forge
libgfortran5-15.2.0 | h68bc16d_16 2.4 MB conda-forge
libglib-2.86.3 | h6548e54_0 3.8 MB conda-forge
liblapack-3.11.0 |5_h47877c9_openblas 18 KB conda-forge
libpng-1.6.53 | h421ea60_0 310 KB conda-forge
libsanitizer-15.2.0 | h90f66d4_16 7.3 MB conda-forge
libstdcxx-devel_linux-64-15.2.0| hd446a21_116 19.8 MB conda-forge
libstdcxx-ng-15.2.0 | hdf11a46_16 27 KB conda-forge
libtiff-4.7.1 | h9d88235_1 425 KB conda-forge
pcre2-10.47 | haa7fec5_0 1.2 MB conda-forge
r-base-4.5.2 | h835929b_3 26.1 MB conda-forge
sysroot_linux-64-2.39 | hc4b9eeb_5 39.6 MB conda-forge
------------------------------------------------------------
Total: 221.1 MB
The following NEW packages will be INSTALLED:
_libgcc_mutex conda-forge/linux-64::_libgcc_mutex-0.1-conda_forge
_openmp_mutex conda-forge/linux-64::_openmp_mutex-4.5-2_gnu
_r-mutex conda-forge/noarch::_r-mutex-1.0.1-anacondar_1
binutils_impl_lin~ conda-forge/linux-64::binutils_impl_linux-64-2.45-default_hfdba357_105
bwidget conda-forge/linux-64::bwidget-1.10.1-ha770c72_1
bzip2 conda-forge/linux-64::bzip2-1.0.8-hda65f42_8
c-ares conda-forge/linux-64::c-ares-1.34.6-hb03c661_0
ca-certificates conda-forge/noarch::ca-certificates-2026.1.4-hbd8a1cb_0
cairo conda-forge/linux-64::cairo-1.18.4-h3394656_0
curl conda-forge/linux-64::curl-8.17.0-h4e3cde8_1
font-ttf-dejavu-s~ conda-forge/noarch::font-ttf-dejavu-sans-mono-2.37-hab24e00_0
font-ttf-inconsol~ conda-forge/noarch::font-ttf-inconsolata-3.000-h77eed37_0
font-ttf-source-c~ conda-forge/noarch::font-ttf-source-code-pro-2.038-h77eed37_0
font-ttf-ubuntu conda-forge/noarch::font-ttf-ubuntu-0.83-h77eed37_3
fontconfig conda-forge/linux-64::fontconfig-2.15.0-h7e30c49_1
fonts-conda-ecosy~ conda-forge/noarch::fonts-conda-ecosystem-1-0
fonts-conda-forge conda-forge/noarch::fonts-conda-forge-1-hc364b38_1
freetype conda-forge/linux-64::freetype-2.14.1-ha770c72_0
fribidi conda-forge/linux-64::fribidi-1.0.16-hb03c661_0
gcc_impl_linux-64 conda-forge/linux-64::gcc_impl_linux-64-15.2.0-hc5723f1_16
gfortran_impl_lin~ conda-forge/linux-64::gfortran_impl_linux-64-15.2.0-h281d09f_16
graphite2 conda-forge/linux-64::graphite2-1.3.14-hecca717_2
gsl conda-forge/linux-64::gsl-2.7-he838d99_0
gxx_impl_linux-64 conda-forge/linux-64::gxx_impl_linux-64-15.2.0-hda75c37_16
harfbuzz conda-forge/linux-64::harfbuzz-12.2.0-h15599e2_0
icu conda-forge/linux-64::icu-75.1-he02047a_0
kernel-headers_li~ conda-forge/noarch::kernel-headers_linux-64-6.12.0-he073ed8_5
keyutils conda-forge/linux-64::keyutils-1.6.3-hb9d3cd8_0
krb5 conda-forge/linux-64::krb5-1.21.3-h659f571_0
ld_impl_linux-64 conda-forge/linux-64::ld_impl_linux-64-2.45-default_hbd61a6d_105
lerc conda-forge/linux-64::lerc-4.0.0-h0aef613_1
libblas conda-forge/linux-64::libblas-3.11.0-5_h4a7cf45_openblas
libcblas conda-forge/linux-64::libcblas-3.11.0-5_h0358290_openblas
libcurl conda-forge/linux-64::libcurl-8.17.0-h4e3cde8_1
libdeflate conda-forge/linux-64::libdeflate-1.25-h17f619e_0
libedit conda-forge/linux-64::libedit-3.1.20250104-pl5321h7949ede_0
libev conda-forge/linux-64::libev-4.33-hd590300_2
libexpat conda-forge/linux-64::libexpat-2.7.3-hecca717_0
libffi conda-forge/linux-64::libffi-3.5.2-h9ec8514_0
libfreetype conda-forge/linux-64::libfreetype-2.14.1-ha770c72_0
libfreetype6 conda-forge/linux-64::libfreetype6-2.14.1-h73754d4_0
libgcc conda-forge/linux-64::libgcc-15.2.0-he0feb66_16
libgcc-devel_linu~ conda-forge/noarch::libgcc-devel_linux-64-15.2.0-hcc6f6b0_116
libgcc-ng conda-forge/linux-64::libgcc-ng-15.2.0-h69a702a_16
libgfortran conda-forge/linux-64::libgfortran-15.2.0-h69a702a_16
libgfortran-ng conda-forge/linux-64::libgfortran-ng-15.2.0-h69a702a_16
libgfortran5 conda-forge/linux-64::libgfortran5-15.2.0-h68bc16d_16
libglib conda-forge/linux-64::libglib-2.86.3-h6548e54_0
libgomp conda-forge/linux-64::libgomp-15.2.0-he0feb66_16
libiconv conda-forge/linux-64::libiconv-1.18-h3b78370_2
libjpeg-turbo conda-forge/linux-64::libjpeg-turbo-3.1.2-hb03c661_0
liblapack conda-forge/linux-64::liblapack-3.11.0-5_h47877c9_openblas
liblzma conda-forge/linux-64::liblzma-5.8.1-hb9d3cd8_2
libnghttp2 conda-forge/linux-64::libnghttp2-1.67.0-had1ee68_0
libopenblas conda-forge/linux-64::libopenblas-0.3.30-pthreads_h94d23a6_4
libpng conda-forge/linux-64::libpng-1.6.53-h421ea60_0
libsanitizer conda-forge/linux-64::libsanitizer-15.2.0-h90f66d4_16
libssh2 conda-forge/linux-64::libssh2-1.11.1-hcf80075_0
libstdcxx conda-forge/linux-64::libstdcxx-15.2.0-h934c35e_16
libstdcxx-devel_l~ conda-forge/noarch::libstdcxx-devel_linux-64-15.2.0-hd446a21_116
libstdcxx-ng conda-forge/linux-64::libstdcxx-ng-15.2.0-hdf11a46_16
libtiff conda-forge/linux-64::libtiff-4.7.1-h9d88235_1
libuuid conda-forge/linux-64::libuuid-2.41.3-h5347b49_0
libwebp-base conda-forge/linux-64::libwebp-base-1.6.0-hd42ef1d_0
libxcb conda-forge/linux-64::libxcb-1.17.0-h8a09558_0
libzlib conda-forge/linux-64::libzlib-1.3.1-hb9d3cd8_2
make conda-forge/linux-64::make-4.4.1-hb9d3cd8_2
ncurses conda-forge/linux-64::ncurses-6.5-h2d0b736_3
openssl conda-forge/linux-64::openssl-3.6.0-h26f9b46_0
pango conda-forge/linux-64::pango-1.56.4-hadf4263_0
pcre2 conda-forge/linux-64::pcre2-10.47-haa7fec5_0
pixman conda-forge/linux-64::pixman-0.46.4-h54a6638_1
pthread-stubs conda-forge/linux-64::pthread-stubs-0.4-hb9d3cd8_1002
r-base conda-forge/linux-64::r-base-4.5.2-h835929b_3
readline conda-forge/linux-64::readline-8.3-h853b02a_0
sed conda-forge/linux-64::sed-4.9-h6688a6e_0
sysroot_linux-64 conda-forge/noarch::sysroot_linux-64-2.39-hc4b9eeb_5
tk conda-forge/linux-64::tk-8.6.13-noxft_ha0e22de_103
tktable conda-forge/linux-64::tktable-2.10-h8d826fa_7
tzdata conda-forge/noarch::tzdata-2025c-hc9c84f9_1
xorg-libice conda-forge/linux-64::xorg-libice-1.1.2-hb9d3cd8_0
xorg-libsm conda-forge/linux-64::xorg-libsm-1.2.6-he73a12e_0
xorg-libx11 conda-forge/linux-64::xorg-libx11-1.8.12-h4f16b4b_0
xorg-libxau conda-forge/linux-64::xorg-libxau-1.0.12-hb03c661_1
xorg-libxdmcp conda-forge/linux-64::xorg-libxdmcp-1.1.5-hb03c661_1
xorg-libxext conda-forge/linux-64::xorg-libxext-1.3.6-hb9d3cd8_0
xorg-libxrender conda-forge/linux-64::xorg-libxrender-0.9.12-hb9d3cd8_0
xorg-libxt conda-forge/linux-64::xorg-libxt-1.3.1-hb9d3cd8_0
zstd conda-forge/linux-64::zstd-1.5.7-hb78ec9c_6
Proceed ([y]/n)? y
Downloading and Extracting Packages:
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
# packages in environment at /home/olebi/miniforge3/envs/r_env:
#
# Name Version Build Channel
_libgcc_mutex 0.1 conda_forge conda-forge
_openmp_mutex 4.5 2_gnu conda-forge
_r-mutex 1.0.1 anacondar_1 conda-forge
binutils_impl_linux-64 2.45 default_hfdba357_105 conda-forge
bwidget 1.10.1 ha770c72_1 conda-forge
bzip2 1.0.8 hda65f42_8 conda-forge
c-ares 1.34.6 hb03c661_0 conda-forge
ca-certificates 2026.1.4 hbd8a1cb_0 conda-forge
cairo 1.18.4 h3394656_0 conda-forge
curl 8.17.0 h4e3cde8_1 conda-forge
font-ttf-dejavu-sans-mono 2.37 hab24e00_0 conda-forge
font-ttf-inconsolata 3.000 h77eed37_0 conda-forge
font-ttf-source-code-pro 2.038 h77eed37_0 conda-forge
font-ttf-ubuntu 0.83 h77eed37_3 conda-forge
fontconfig 2.15.0 h7e30c49_1 conda-forge
fonts-conda-ecosystem 1 0 conda-forge
fonts-conda-forge 1 hc364b38_1 conda-forge
freetype 2.14.1 ha770c72_0 conda-forge
fribidi 1.0.16 hb03c661_0 conda-forge
gcc_impl_linux-64 15.2.0 hc5723f1_16 conda-forge
gfortran_impl_linux-64 15.2.0 h281d09f_16 conda-forge
graphite2 1.3.14 hecca717_2 conda-forge
gsl 2.7 he838d99_0 conda-forge
gxx_impl_linux-64 15.2.0 hda75c37_16 conda-forge
harfbuzz 12.2.0 h15599e2_0 conda-forge
icu 75.1 he02047a_0 conda-forge
kernel-headers_linux-64 6.12.0 he073ed8_5 conda-forge
keyutils 1.6.3 hb9d3cd8_0 conda-forge
krb5 1.21.3 h659f571_0 conda-forge
ld_impl_linux-64 2.45 default_hbd61a6d_105 conda-forge
lerc 4.0.0 h0aef613_1 conda-forge
libblas 3.11.0 5_h4a7cf45_openblas conda-forge
libcblas 3.11.0 5_h0358290_openblas conda-forge
libcurl 8.17.0 h4e3cde8_1 conda-forge
libdeflate 1.25 h17f619e_0 conda-forge
libedit 3.1.20250104 pl5321h7949ede_0 conda-forge
libev 4.33 hd590300_2 conda-forge
libexpat 2.7.3 hecca717_0 conda-forge
libffi 3.5.2 h9ec8514_0 conda-forge
libfreetype 2.14.1 ha770c72_0 conda-forge
libfreetype6 2.14.1 h73754d4_0 conda-forge
libgcc 15.2.0 he0feb66_16 conda-forge
libgcc-devel_linux-64 15.2.0 hcc6f6b0_116 conda-forge
libgcc-ng 15.2.0 h69a702a_16 conda-forge
libgfortran 15.2.0 h69a702a_16 conda-forge
libgfortran-ng 15.2.0 h69a702a_16 conda-forge
libgfortran5 15.2.0 h68bc16d_16 conda-forge
libglib 2.86.3 h6548e54_0 conda-forge
libgomp 15.2.0 he0feb66_16 conda-forge
libiconv 1.18 h3b78370_2 conda-forge
libjpeg-turbo 3.1.2 hb03c661_0 conda-forge
liblapack 3.11.0 5_h47877c9_openblas conda-forge
liblzma 5.8.1 hb9d3cd8_2 conda-forge
libnghttp2 1.67.0 had1ee68_0 conda-forge
libopenblas 0.3.30 pthreads_h94d23a6_4 conda-forge
libpng 1.6.53 h421ea60_0 conda-forge
libsanitizer 15.2.0 h90f66d4_16 conda-forge
libssh2 1.11.1 hcf80075_0 conda-forge
libstdcxx 15.2.0 h934c35e_16 conda-forge
libstdcxx-devel_linux-64 15.2.0 hd446a21_116 conda-forge
libstdcxx-ng 15.2.0 hdf11a46_16 conda-forge
libtiff 4.7.1 h9d88235_1 conda-forge
libuuid 2.41.3 h5347b49_0 conda-forge
libwebp-base 1.6.0 hd42ef1d_0 conda-forge
libxcb 1.17.0 h8a09558_0 conda-forge
libzlib 1.3.1 hb9d3cd8_2 conda-forge
make 4.4.1 hb9d3cd8_2 conda-forge
ncurses 6.5 h2d0b736_3 conda-forge
openssl 3.6.0 h26f9b46_0 conda-forge
pango 1.56.4 hadf4263_0 conda-forge
pcre2 10.47 haa7fec5_0 conda-forge
pixman 0.46.4 h54a6638_1 conda-forge
pthread-stubs 0.4 hb9d3cd8_1002 conda-forge
r-base 4.5.2 h835929b_3 conda-forge
readline 8.3 h853b02a_0 conda-forge
sed 4.9 h6688a6e_0 conda-forge
sysroot_linux-64 2.39 hc4b9eeb_5 conda-forge
tk 8.6.13 noxft_ha0e22de_103 conda-forge
tktable 2.10 h8d826fa_7 conda-forge
tzdata 2025c hc9c84f9_1 conda-forge
xorg-libice 1.1.2 hb9d3cd8_0 conda-forge
xorg-libsm 1.2.6 he73a12e_0 conda-forge
xorg-libx11 1.8.12 h4f16b4b_0 conda-forge
xorg-libxau 1.0.12 hb03c661_1 conda-forge
xorg-libxdmcp 1.1.5 hb03c661_1 conda-forge
xorg-libxext 1.3.6 hb9d3cd8_0 conda-forge
xorg-libxrender 0.9.12 hb9d3cd8_0 conda-forge
xorg-libxt 1.3.1 hb9d3cd8_0 conda-forge
zstd 1.5.7 hb78ec9c_6 conda-forgeSection 3: Exporting and Importing Environments
Background
A powerful feature of Conda is the ability to share environment configurations with collaborators. By exporting an environment to a file, you can create a “snapshot” of all installed packages and dependencies. This is essential for reproducibility in research, as others can recreate the exact environment to ensure consistency in analyses and results. Using Conda environment files can save time and reduce errors, especially when working on collaborative projects.
Removing unused environments and packages helps keep your Conda installation clean and organized, conserving storage space and reducing potential conflicts. Conda makes it easy to remove entire environments or individual packages, allowing you to focus only on the active dependencies you need for your current work.
Section 4: Exercises
In the following exercises, you are going to export your environment to a YAML file and use that file to recreate the environment after deleting it (the same approach could be used to reproduce the environment on a different device). Here are the commands you need to know:
| Code | Description |
|---|---|
conda env export > environment.yml |
Save active environment configuration to environment.yml |
conda remove -n env_name --all |
Remove the environment env_name completely |
conda remove package_name |
Remove package_name from the active environment |
conda env create -f environment.yml |
Create an environment from the file environment.yml |
conda env list |
List all existing Conda environments |
Exercise: Activate the py_env environment from the previous section, then export its content to a file called environment.yml.
Solution
conda activate py_env
conda env export > environment.ymlExercise: Deactivate and delete py_env. List all environments to confirm it was deleted.
Solution
conda deactivate
conda remove -n py_env --all
conda info --envs
Remove all packages in environment /home/olebi/miniforge3/envs/py_env:
No packages found in /home/olebi/miniforge3/envs/py_env. Continuing environment removal
Everything found within the environment (/home/olebi/miniforge3/envs/py_env), including any conda environment configurations and any non-conda files, will be deleted. Do you wish to continue?
(y/[n])? y
# conda environments:
#
base /home/olebi/miniforge3
r_env /home/olebi/miniforge3/envs/r_env
test_env /home/olebi/miniforge3/envs/test_env
test_env2 /home/olebi/miniforge3/envs/test_env2Exercise: Recreate py_env from the environment.yml file, then list all environments again.
Solution
conda env create -f environment.yml
conda env list
Channels:
- conda-forge
Platform: linux-64
Collecting package metadata (repodata.json): done
Solving environment: done
Downloading and Extracting Packages:
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate py_env
#
# To deactivate an active environment, use
#
# $ conda deactivate
# conda environments:
#
base /home/olebi/miniforge3
py_env /home/olebi/miniforge3/envs/py_env
r_env /home/olebi/miniforge3/envs/r_env
test_env /home/olebi/miniforge3/envs/test_env
test_env2 /home/olebi/miniforge3/envs/test_env2Exercise: Verify the recreation by activating py_env and listing the installed packages.
Solution
conda activate py_env
conda list
# packages in environment at /home/olebi/miniforge3/envs/py_env:
#
# Name Version Build Channel
_libgcc_mutex 0.1 conda_forge conda-forge
_openmp_mutex 4.5 2_gnu conda-forge
bzip2 1.0.8 hda65f42_8 conda-forge
ca-certificates 2026.1.4 hbd8a1cb_0 conda-forge
icu 78.1 h33c6efd_0 conda-forge
ld_impl_linux-64 2.45 default_hbd61a6d_105 conda-forge
libblas 3.11.0 5_h4a7cf45_openblas conda-forge
libcblas 3.11.0 5_h0358290_openblas conda-forge
libexpat 2.7.3 hecca717_0 conda-forge
libffi 3.5.2 h9ec8514_0 conda-forge
libgcc 15.2.0 he0feb66_16 conda-forge
libgcc-ng 15.2.0 h69a702a_16 conda-forge
libgfortran 15.2.0 h69a702a_16 conda-forge
libgfortran5 15.2.0 h68bc16d_16 conda-forge
libgomp 15.2.0 he0feb66_16 conda-forge
liblapack 3.11.0 5_h47877c9_openblas conda-forge
liblzma 5.8.1 hb9d3cd8_2 conda-forge
libnsl 2.0.1 hb9d3cd8_1 conda-forge
libopenblas 0.3.30 pthreads_h94d23a6_4 conda-forge
libsqlite 3.51.1 hf4e2dac_1 conda-forge
libstdcxx 15.2.0 h934c35e_16 conda-forge
libuuid 2.41.3 h5347b49_0 conda-forge
libxcrypt 4.4.36 hd590300_1 conda-forge
libzlib 1.3.1 hb9d3cd8_2 conda-forge
ncurses 6.5 h2d0b736_3 conda-forge
numpy 2.4.0 py312h33ff503_0 conda-forge
openssl 3.6.0 h26f9b46_0 conda-forge
pip 25.3 pyh8b19718_0 conda-forge
python 3.12.12 hd63d673_1_cpython conda-forge
python_abi 3.12 8_cp312 conda-forge
readline 8.3 h853b02a_0 conda-forge
setuptools 80.9.0 pyhff2d567_0 conda-forge
tk 8.6.13 noxft_ha0e22de_103 conda-forge
tzdata 2025c hc9c84f9_1 conda-forge
wheel 0.45.1 pyhd8ed1ab_1 conda-forge
zstd 1.5.7 hb78ec9c_6 conda-forgeBonus: Remove all the environments you don’t want to keep after this session.