コンテナを起動した時にvenvをactivateする方法が分からなかったが、%runscriptに書けば動いた。

BootStrap: docker
From: nvcr.io/nvidia/cuda:12.6.3-base-ubuntu24.04

%setup
    setup_dir="${SINGULARITY_ROOTFS}/usr/local/python_env"
    mkdir -p "${setup_dir}"
    cp "./requirements.txt" "${setup_dir}/requirements.txt"

%post
    export DEBIAN_FRONTEND=noninteractive
    export TZ=Asia/Tokyo

    apt update && \
    apt install -y \
        tzdata \
        locales \
        curl  \
        git \
        tk-dev \
        htop \
        language-pack-ja \
        libhdf5-serial-dev \
        python3 \
        python3-pip \
        python3-venv

    export install_base_dir="/usr/local"

    # Setup locale
    localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8

    export python_env_install_dir="${install_base_dir}/python_env"
    export venv_dir="${python_env_install_dir}/.venv"
    cd "${python_env_install_dir}"
    python3 -m venv "${venv_dir}"
    . "${venv_dir}/bin/activate"
    pip install -r "${python_env_install_dir}/requirements.txt"
    
    # Clean up
    apt clean
    rm -rf /var/lib/apt/lists/*

%runscript
    #!/bin/bash
    set -euo pipefail
    source /usr/local/python_env/.venv/bin/activate

    exec "$@"

%environment
    export LANG=en_US.utf8
    export DEBIAN_FRONTEND=noninteractive
    export TZ=Asia/Tokyo