Charles Peterson
Welcome to Hoffman2 Happy Hour!
The H2HH are designed to be short interactive talks that focus on a certain aspect of HPC.
Any suggestions for upcoming workshops, email me at cpeterson@oarc.ucla.edu
This presentation can be found on our UCLA OARC’s github repo.
View slides:
PDF format: H2HH_anaconda.pdf
html format:
Note
This presentation was built with Quarto and RStudio.
H2HH_anaconda.qmd
Easy install many python and R packages with simple conda
commands
Create isolated python/R environments for different projects
Checks and solve for possible version conflicts when installing packages
Share conda env on different systems.
On Hoffman2, Anaconda is installed and can be used by loading modules
Important
By using anaconda, you do NOT need to load any other python/R modules. The python/R builds will be available via anaconda.
Using other python build might cause conflicts with your anaconda python (or R)
$HOME/.conda
pip
for pythonCreating a new conda environment
-n
option will name your new conda envSee list of all your environments that you have created
Start (activate) your conda environment
Activating the conda env gives access to the software within the env
This version of python
and R
is installed locally in your conda env and is different from the builds of python on Hoffman2.
You can see location of python in your env and check the version.
Important
You do NOT need to load the python module if you installed python via anaconda.
You may be familiar with using Anaconda on your local machine.
Warning
Do not use conda’s default base
env
When conda is installed, it creates a conda env named base
that you may see when running conda env list
Warning
Do not run conda init
on H2.
You may see messages or online tips about running the conda init
command.
This initializes conda but is NOT NEEDED to run on Hoffman2
While this does setup conda, it will change ~/.bashrc and may cause conflicts using different versions/envs.
Loading the anaconda module will already setup conda.
Once your conda env is activated, you can install more packages with
conda install
conda create -n myconda
conda activate myconda
conda install python=3.9 pandas scipy tensorflow -c conda-forge
Note
The -c
option in conda is for the “conda channel”. The conda channels are different locations where packages are stored. Examples are ‘conda-forge’, ‘bioconda’, ‘defaults’, etc. Conda will search through the available channels for the request packages to install.
You can use pip
when you are in a conda env
Tip
When using pip/pip3 in a conda env, you do NOT need to have --user
. Using just pip
will install the package inside the conda env. If you use --user
, it will install the package in outside of the conda env, inside of ~/.local
and may cause conflicts with other python builds or conda env’s you have.
By default, when you install a conda env, it will install it at ~/.conda
You can change this location, esp if you are low in space at $HOME
Example: Using Pytorch to fit a polynomial function from a sin function
File: pytorch_ex.py
#!/bin/bash
#$ -cwd
#$ -j y
#$ -l h_rt=1:00:00,h_data=5G
#$ -pe shared 1
# load the anaconda module
. /u/local/Modules/default/init/modules.sh
module load anaconda3/2020.11
# Activate the 'mypytorch' conda env
conda activate mypytorch
#Running python code
python pytorch_ex.py > pytorch_ex.out
The mypytorch
conda env has already been created
Find software that is available on Anaconda’s package repo
Here, you can search for software and other packages. It will also explain what conda commands you will need in order to install them to your conda env.
You can create a conda file from a environment.yml
file
You can create a conda env with all these packages by running:
An .yml
file can be created from an existing conda env so you can create the same conda env.
This file can be shared with others to reproduce any conda env.
Tip
We have a collection of .yml
files that we made to use on Hoffman2
While Hoffman2 already has Anaconda installed, you may need to install Anaconda on a separate machine or another HPC resource.
Visit https://repo.anaconda.com/archive/ for all the versions of Anaconda that are available.
In this example, anaconda is install at $HOME/apps/anaconda/2021.11
Tip
Don’t run conda init
Instead, source /CONDA/PATH/etc/profile.d/conda.sh
This will setup Anaconda without changing the ~/.bashrc file
Tip
Miniconda is a good alternative to Anaconda.
It is a Minimal installer for conda that is smaller than Anaconda.
Questions? Comments?
Charles Peterson
Look at for more Hoffman2 workshops at https://idre.ucla.edu/calendar
HPC