using Python on UCL cluster - McGranahanLab/Guidebook GitHub Wiki

Using VENV

Preparing venv

Source desired Python version: source /share/apps/source_files/python/python-3.10.0.source

Choose the location of your virtual environment and create it:

VENV_DIR=/path/to/your/venv/
python3 -m venv $VENV_DIR

Activate the environment, upgrade pip and install modules:

source $VENV_DIR/bin/activate
pip install --upgrade pip
pip install pandas

Submitting Python jobs

Place this block (with updated path to VENV_DIR) with your .sh file.

#$ -l tmem=2G
#$ -l h_vmem=2G
#$ -l h_rt=0:30:0
#$ -S /bin/bash

VENV_DIR=/path/to/your/venv/
source $VENV_DIR/bin/activate
PYTHON_VERSION=$(python3 --version | cut -d ' ' -f 2)
export LD_LIBRARY_PATH=/share/apps/python-$PYTHON_VERSION-shared/lib:$LD_LIBRARY_PATH

python3 my_script.py