Conda
Conda
Conda is a package and environment management system that allows users to create isolated Python environments with their own libraries and dependencies. This example shows a simple workflow for running a Python script using Conda.
1. Check available Anaconda modules
module avail Anaconda
Lists the Anaconda module versions installed on the cluster.
2. Load the module
module load Anaconda3
Loads the default Anaconda3 module.
3. Create a new environment
conda create --yes --name myenv python=3.10
Creates an isolated Conda environment named myenv with a specific Python version, so installed packages don't affect the system Python or other users.
4. Activate the environment
conda activate myenv
After activating, your shell prompt will change to show (myenv).
5. Install required packages
To install packages inside your Conda environment, you can use either conda install or pip install:
conda install <package>
pip install <package>
You can also update an existing environment from an environment file(.yml):
conda env update --name myenv --file env.yml
Where:
- myenv is the name of the Conda environment to update.
- env.yml is the YAML file containing the required packages and dependencies.
6. Run the script
To run the script, use the SLURM job scheduler. You can submit your job using a .sh script. Below is an example of such a script:
#!/bin/bash
#SBATCH --job-name=python_job
#SBATCH --output=python_job_%j.out
#SBATCH --error=python_job_%j.err
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=1
#SBATCH --time=00:30:00
module load Anaconda3
source activate <path-to-your-conda-env>
python my_script.py
Submitting the job:
sbatch my_job.sh
You can check the job status using the command:
squeue --me
Other useful commands
conda env list # list all your environments
conda deactivate # deactivate the current environment
conda env remove -n myenv # remove an environment