Working with Conda/Miniconda/Anaconda¶
Conda is an open source environment and package manager. Miniconda is a free installer for Conda, Python, and a few other useful packages. Anaconda is also a package manager that has a much larger number of packages that you can install. A question that frequently comes up is “Should I use Anaconda or Miniconda?” The Conda documentation site has a topic that can help you to decide which package manager to use: https://docs.conda.io/projects/conda/en/latest/user-guide/install/download.html#anaconda-or-miniconda.
Creating a Conda virtual environment with Anaconda¶
Using a locally installed Conda virtual environment is highly recommended so that you can install the specific packages that you need. You can also have more than one environment with different packages for testing purposes. This procedure uses the Anaconda module already loaded on Discovery.
- To check what version of Python you have installed, type
- To load anaconda, type
module load anaconda3/3.7.
- To create your environment, type
conda create -n <yourenvironmentname> python=3.7 anaconda, where <yourenvironmentname> is the name you want to give your environment. Tip: to see a list of all of your conda environments, type
conda info -e.
- Follow the prompts to complete the Conda install.
- To activate your Conda environment, type
source activate <yourenvironmentname>. Note that
conda activatewill not work on Discovery with this version.
- To install a specific package, type
conda install -n <yourenvironmentname> [package].
- To deactivate the current, active Conda environment, type
- To delete a Conda environment and all of its related packages, type
conda remove -n <yourenvironmentname> --all.
Working with a Miniconda environment¶
This procedure assumes that you have not installed Miniconda previously. If you need to update Miniconda, don’t use the installation procedure. Use the
conda update command. This procedure uses the Miniconda3 version with Python version 3.8 in step 2, although there are other versions you can install, such as
Miniconda3 with Python 3.7.
To install Miniconda:
- If you are on a login node, move to a compute node by typing
srun --partition=short --nodes=1 --cpus-per-task=1 --pty /bin/bash.
wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.shto get the latest version of Miniconda.
sha256sum Miniconda3-latest-Linux-x86_64.shto check the hash key of the package.
bash Miniconda3-latest-Linux-x86_64.shto start the installation.
Enterto review the license agreement.
yesto agree to the license agreement.
Enterto accept the default installation location (your /home directory, e.g. /home/<yourusername>/miniconda3).
yesif asked to initialize Miniconda using conda init.
source miniconda3/bin/activateto activate the miniconda environment.
After installing and activating Miniconda, you can create a Conda environment. In the example below, the Conda envinronment is named “my-python38environment” and installs Python version 3.8.
- After completing steps 1 through 9 in the previous procedure, type
conda create --name my-python38environment python=3.8.
yif asked to proceed with the installation.
conda activate my-python38environmentto activate the environment.
To deactivate the environment, type
conda deactivate. You can type this command again to deactivate the Miniconda environment.