Breadcrumb
Conda Environments
Conda
The clas-unix team makes conda available on most of the linux systems in the /opt/anaconda3 directory. The conda command should already be in the search path of most users. Conda is a system for package management of multiple programming languages, but the most commonly used in CLAS is python.
Conda Python environments
use the Cheat Sheet as a reference for commands.
Python environments act as containers that allow you to select a specific version of python and python modules to use for your project. Each environment can only have one version of python, and one version of each module installed. The conda environments are self contained and distinct from the system installed python. You can have multiple conda python environments, they just need to be installed in different directories.
The advantages of using conda environments:
- The conda environments can be configured by regular users
- The environment allows you to select a specific versions of python
- Conda provides dependency resolution, so if you provide a list packages needed, it will attempt to solve for the prover version of python and other libraries that allow all of the packages requested to work.
- The specifics of a configured conda environment can be exported as a yaml file that can be used to recreate the environment on a different server
- conda environments have some limited management functionality that allows for showing changes and reverting most changes to the environment
- The packages and modules in conda are built to work with each other in a consistent manner, but pip install is available as a last resort.
Verify Conda is available
(base) -bash-4.2$ conda --version conda 4.9.2 |
Pre-requisite check
When using conda, it writes all of the packages you download to a cache in your home directory. If your home directory is on NFS, you will overrun your quota.
# user with an NFS home directory # user with a local home directory won't have any output after running the command |
If you do have an NFS home directory, you will need to create a local directory to hold the package cache.
# assumes /data/not_backed_up exists, but use any local directory where there is space and you have write access mkdir -p /data/not_backed_up/$USER/conda_pkgs conda config --add pkgs_dirs "/data/not_backed_up/$USER/conda_pkgs" |
All of the examples below assume that you have a local home directory. If you do not, set up your environments on local disk rather than in your home directory.
Create a Conda Environment
Identify a location that you have write access to to store the environment (in this case /home/ddholstad/conda_environments/) . We will create an environment that contains both nltk and numpy, letting conda select the newest version of python the these packages both work on. Conda will automatically download and install any packages that are prerequisites for the requested packages.
- conda will create the directory
- solve for dependencies
- create a base python installation
- install required packages
(base) -bash-4.2$ conda create -p /home/ddholstad/conda_environments/example1 nltk numpy ## Package Plan ## environment location: /home/ddholstad/conda_environments/example1 added / updated specs: The following packages will be downloaded: package | build The following NEW packages will be INSTALLED: _libgcc_mutex pkgs/main/linux-64::_libgcc_mutex-0.1-main Proceed ([y]/n)? y Downloading and Extracting Packages
|
Activate the environment
(base) -bash-4.2$ conda activate /home/ddholstad/conda_environments/example1
|
Install additional packages as needed.
(/home/ddholstad/conda_environments/example1) -bash-4.2$ conda install pandas ==> WARNING: A newer version of conda exists. <== Please update conda by running $ conda update -n base -c defaults conda
## Package Plan ## environment location: /home/ddholstad/conda_environments/example1 added / updated specs: The following packages will be downloaded: package | build The following NEW packages will be INSTALLED: bottleneck pkgs/main/linux-64::bottleneck-1.3.2-py39hdd57654_1 Proceed ([y]/n)? y Downloading and Extracting Packages |
Export A conda environment:
You can export your environment using the export command. Note use: "conda env export > envname.yml" to save as a file
/home/ddholstad/conda_environments/example1) -bash-4.2$ conda env export name: /home/ddholstad/conda_environments/example1 |
Remove an environment
(/home/ddholstad/conda_environments/example1) -bash-4.2$ conda deactivate Remove all packages in environment /home/ddholstad/conda_environments/example1: (base) -bash-4.2$ ls -l /home/ddholstad/conda_environments/example1 |
create an environment from a yaml file
(base) -bash-4.2$ conda env create -f example1.yml -p /home/ddholstad/conda_environments/example1 ==> WARNING: A newer version of conda exists. <== Please update conda by running $ conda update -n base -c defaults conda Preparing transaction: done |