Skip to content

Using Conda Environments in Scripts

Now that we have our environment ready, we can use it from the command line or a script.

Activation of your environment is really only needed for package installation. An environment can be used in a job script just by adding the path of its bin directory to $PATH in your job script.

# Set path to environment we want and pre-pend to PATH variable
export PATH=/blue/mygroup/user/project42/.conda/bin:$PATH

# Run my amazing python script
python amazing_script.py

An environment can also be activated in a job script using conda activate:

module load conda
conda activate my_env

# Run my amazing python script
python amazing_script.py

Get the bin directory path for Conda environmentsΒΆ

If you are using an environment by modifying the PATH environment varialble, you can find the proper path by activating the environment and using the which python command.

    [username@login8 ~]$ module load conda
    [username@login8 ~]$ conda activate my_env
    (my_env) [username@login8 ~]$ which python
    /blue/mygroup/username/.conda/envs/my_env/bin/python
    (my_env) [username@login8 ~]$

In this case, the path we would want to add is /blue/mygroup/username/.conda/envs/my_env/bin/

Next: Creating Jupyter Kernels