Using Conda Environments in Scripts
Activation of your environment is really 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
Expand to see the details of a sample script with the export command
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Adjust the path as needed for your environment. The path should include the bin
folder as shown above.
Get the Python Path for Name-Based EnvironmentsΒΆ
If you are using name-based environments, it is still best practice to add the path, rather than activating the environment. You can find the proper path by activating the environment and using the which python
command.
Expand to see the details of getting the Python path from a name-based environment
[username@login8 ~]$ module load conda
[username@login8 ~]$ mamba activate my_env
(my_env) [username@login8 ~]$ which python
/blue/mygroup/username/.conda/envs/my_env/bin/python
(nlp_test) [username@login8 ~]$
In this case, the path we would want to add is /blue/mygroup/username/.conda/envs/my_env/bin/