Conda Package and Environment Manager
We use Conda software packages, dependencies, and environments. conda was developed as part of the excellent Anaconda data science toolkit, but we have found that using conda and explicitly managing software environments is more robust over time than using Anaconda.
TODO: Write an intro to conda
Slides notebook from May 2023 group discussion of Python packages and environments:
nbviewer: https://nbviewer.org/github/UBC-MOAD/PythonNotes/blob/main/pkgs-envs/PythonPkgsEnvsSlides-2023.ipynb
GitHub: https://github.com/UBC-MOAD/PythonNotes/blob/main/pkgs-envs/PythonPkgsEnvsSlides-2023.ipynb
Installing Miniforge
Miniforge is a minimal installer for Conda specific to conda-forge. It installs the conda package and environment manager tool, a recent version of Python, the packages that conda depends on, and a small number of other packages that are essential for creating and managing software environments.
The installers for Miniforge are linked on the Miniforge page. You can download them from there, and that is what you should do if you are working on Windows. But for Linux and MacOS you’ll be working with conda on the command-line in terminals sessions, so you might as well get started that way by using wget to download the installer script into your home directory.
On Linux, macOS and Windows Subsystem for Linux (WSL) use:
$ wget "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"
The installation instructions are in the “Unix-like platforms” section of the README of https://github.com/conda-forge/miniforge. In short:
Run the installer script via bash:
$ bash Miniforge3-$(uname)-$(uname -m).sh
Follow the prompts on the screen. Accept the defaults offered for all of the settings
To make the changes take effect, close and then re-open your terminal window.
Test your installation. In your terminal window, run the command conda list. A list of installed packages appears if it has been installed correctly; it looks something like:
conda Configuration
conda uses configuration settings in your $HOME/.condarc file to supplement its default configuration.
You need to set up this configuration on each machine that you use conda on;
i.e. on your laptop,
and on the Waterhole workstation that you use
(which will cover all of the Waterhole/Ocean machines).
The conda config command is how you interact with the $HOME/.condarc file.
Start by telling conda where you want to store your environments:
$ conda config --prepend envs_dirs $HOME/conda_envs/
$ mkdir $HOME/conda_envs/
The first of those lines tells conda that you want to put your environments
in a directory called $HOME/conda_envs/.
The second line creates that directory.
Storing environment directory trees outside of the $HOME/miniforge3/ directory
created by the installer means that if you need to re-install Miniforge
you can do so without destroying all of your environments.
If you want to see all of the conda configuration settings
(both the defaults,
and the supplements from your $HOME/.condarc file,
you can use:
$ conda config --show
There are many, many things that you can configure in conda. If you want to see all of the gory details, please see the conda config docs.