Environment Creation
Before we can run conda
on HiPerGator, we need to load the conda
module:
module load conda
Create Your Environment¶
Create a Name Based Environment¶
To create your first name based (see path based instructions below) conda environment, run the following command. For example, to create an environment named my_env
:
conda create -n my_env
Expand to see example command and output
[username@login7 ~]$ conda create -n my_env
Looking for: []
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
To activate this environment, use
$ conda activate my_env
To deactivate an active environment, use
$ conda deactivate
[username@login7 ~]$
Tip
When creating a Conda environment you can also install Conda packages as needed at the same time. i.e:
conda create -n another_env python=3.11 pytorch numpy=2.22
Create a Path Based Environment¶
To create a path based conda
environment use the -p
argument. For example, to create a path based enviroment at /blue/mygroup/share/project42/conda/envs/hfrl/
conda create -p /blue/mygroup/share/project42/conda/envs/another_env/
Expand to see example command and output
[username@login7 ~]$ conda create -p /blue/mygroup/share/project42/conda/envs/another_env/
Looking for: []
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
To activate this environment, use
$ conda activate /blue/mygroup/share/project42/conda/envs/another_env/
To deactivate an active environment, use
$ conda deactivate
[username@login7 ~]$
Activate the New Environment¶
To activate our environment:
- For name based environments:
conda activate my_env
- For path based environments:
conda activate /blue/mygroup/share/project42/conda/envs/another_env
Success
Notice that your command prompt changes when you activate an environment to indicate which environment is active, showing that in parentheses before the other information:
(myenv) [username@c0907a-s23 ~]$
Tip
Activation of your environment is only needed for package installation. For using the environment just add the path to its bin directory to $PATH
in your job script.
E.g. If you conda environment at /blue/mygroup/$USER/conda/envs/project1/
, add the following into your job script before executing any commands
export PATH=/blue/mygroup/$USER/conda/envs/project1/bin:$PATH
Adjust the path as needed for your environment. The path should include the bin
folder as shown above.
Once you are done installing packages inside the environment you can use
conda deactivate
Export or Import an Environment¶
Export an Environment¶
Now that you have your environment working, you may want to document its contents and/or share it with others. The environment.yml
file defines the environment and can be used to build a new environment with the same setup.
To export an environment file from an existing environment, run:
conda env export > my_env.yml
You can inspect the contents of this file with cat my_env.yml
. This file defines the packages and versions that make up the environment as it is at this point in time. Note that it also includes packages that were installed via pip
.
Import an Environment¶
If you share the environment yaml file created above with another user, they can create a copy of your environment using the command:
conda env create --file my_env.yml
They may need to edit the last line to change the location to match where they want their environment created.
Other Operations¶
See the Conda project's documentation on managing conda environments.
Group Environments¶
It is possible to create a shared environment accessed by a group on HiPerGator, storing the environment in, for example, /blue/group/share/conda
. In general, this works best if only one user has write access to the environment. All installs should be made by that one user and should be communicated with the other users in the group. It is recommended that user's umask configuration is set to group friendly permissions, such as umask 007. See Sharing Within A Cluster.
Next: Installing Packages