[Python] Check if conda env exists and create if not in bash

Discussão em 'Python' iniciado por Stack, Setembro 3, 2025.

  1. Stack

    Stack Membro Participativo

    I have a build script to run a simple python app. I am trying to set it up that it will run for any user that has conda installed and in their PATH. No other prerequisites. I have that pretty much accomplished but would like to make it more efficient for returning users.

    build_run.sh

    conda init bash
    conda env create --name RUN_ENV --file ../run_env.yml -q --force
    conda activate RUN_ENV
    python run_app.py
    conda deactivate


    I would like to make it that the script checks if RUN_ENV already exists and activates it instead of forcing its creation every time. I tried

    ENVS=$(conda env list | awk '{print }' )
    if [[ conda env list = *"RUN_ENV"* ]]; then
    conda activate RUN_ENV
    else
    conda env create --name RUN_ENV --file ../run_env.yml -q
    conda activate RUN_ENV
    exit
    fi;
    python run_app.py
    conda deactivate


    but it always came back as false and tried to create RUN_ENV

    Continue reading...

Compartilhe esta Página