Skip to content

Using Conda

Steps for using conda (initial setup)

Run these commands to create a new conda environment. You don't need to run these every time you use the environment - you can skip to the next section.

  1. Activate conda:

    source /shared/software/software-environments/miniconda3/bin/activate
    
  2. Create a conda environment. You may have to type Y to confirm. This may take a few minutes to setup.

    conda create --name my_env python=3.12
    
  3. Activate the environemnt

    conda activate my_env
    

    Your shell prompt should now list the environment name:

    (my_env) [user@ip-10... ~]$
    
  4. Install pip or conda packages. You may have to type Y to confirm. This may take a few minutes to install.

    conda install -c conda-forge matplotlib
    pip install numpy pandas
    
  5. [Optional] If you want to use this conda environment from Jupyter, run the

  6. following commands:

    python3 -m pip install ipykernel
    python3 -m ipykernel install --user --name py312
    

Steps for using conda (after initial setup)

  1. Activate conda:

    source /shared/software/software-environments/miniconda3/bin/activate
    
  2. Activate the environment

    conda activate my_env
    

    Your shell prompt should now list the environment name:

    (my_env) [user@ip-10... ~]$
    
  3. Use srun to execute a shell within the slurm job

    srun --time=30:00 --pty /bin/bash
    
  4. You can now run your code from the shell, e.g.:

    python -c "import numpy as np; print('hello world', np.array([1,2,3]))"
    

Find location of your conda environment

Sometimes, you will need to know the folder where your conda environment is stored. This will give you a folder where your conda environment is stored on disk.

After activating your environment (see steps above), you can run:

echo $CONDA_PREFIX

The paths path it prints is the path to your conda folder.