From 46a21899daad0de746b02181abee76a8e304b9be Mon Sep 17 00:00:00 2001 From: Thanarit Date: Fri, 6 Jun 2025 00:14:22 +0700 Subject: [PATCH 1/2] Add support for already activated conda environment setup --- setup.sh | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/setup.sh b/setup.sh index f8378c6..139f105 100755 --- a/setup.sh +++ b/setup.sh @@ -192,18 +192,24 @@ install_python_dependencies() { # Switch to local virtual env echo "Switching to virtual Python environment." if ! inDocker; then - if command -v python3.10 >/dev/null; then + # Check if conda environment is already activated + if [ -n "$CONDA_PREFIX" ]; then + echo "Detected active conda environment: $CONDA_DEFAULT_ENV" + echo "Using existing conda environment at: $CONDA_PREFIX" + # No need to create or activate a venv, conda env is already active + elif command -v python3.10 >/dev/null; then python3.10 -m venv "$DIR/venv" + # Activate the virtual environment + source "$DIR/venv/bin/activate" elif command -v python3 >/dev/null; then python3 -m venv "$DIR/venv" + # Activate the virtual environment + source "$DIR/venv/bin/activate" else echo "Valid python3 or python3.10 binary not found." echo "Cannot proceed with the python steps." return 1 fi - - # Activate the virtual environment - source "$DIR/venv/bin/activate" fi case "$OSTYPE" in @@ -228,11 +234,16 @@ install_python_dependencies() { esac if [ -n "$VIRTUAL_ENV" ] && ! inDocker; then - if command -v deactivate >/dev/null; then - echo "Exiting Python virtual environment." - deactivate + # Don't deactivate if we're using a conda environment that was already active + if [ -z "$CONDA_PREFIX" ] || [ "$VIRTUAL_ENV" != "$CONDA_PREFIX" ]; then + if command -v deactivate >/dev/null; then + echo "Exiting Python virtual environment." + deactivate + else + echo "deactivate command not found. Could still be in the Python virtual environment." + fi else - echo "deactivate command not found. Could still be in the Python virtual environment." + echo "Keeping conda environment active as it was already activated before running this script." fi fi } From 271bcb3bd9803c17fdac5dc6563becfe2c83d9fc Mon Sep 17 00:00:00 2001 From: Thanarit Date: Fri, 6 Jun 2025 00:33:16 +0700 Subject: [PATCH 2/2] Modify the GUI script to check for and handle conda env --- gui.sh | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/gui.sh b/gui.sh index c6502d3..de6177d 100755 --- a/gui.sh +++ b/gui.sh @@ -42,10 +42,17 @@ SCRIPT_DIR=$(cd -- "$(dirname -- "$0")" && pwd) # Step into GUI local directory cd "$SCRIPT_DIR" || exit 1 -if [ -d "$SCRIPT_DIR/venv" ]; then +# Check if conda environment is already activated +if [ -n "$CONDA_PREFIX" ]; then + echo "Using existing conda environment: $CONDA_DEFAULT_ENV" + echo "Conda environment path: $CONDA_PREFIX" +elif [ -d "$SCRIPT_DIR/venv" ]; then + echo "Activating venv..." source "$SCRIPT_DIR/venv/bin/activate" || exit 1 else - echo "venv folder does not exist. Not activating..." + echo "No conda environment active and venv folder does not exist." + echo "Please run setup.sh first or activate a conda environment." + exit 1 fi # Check if LD_LIBRARY_PATH environment variable exists @@ -87,8 +94,12 @@ fi #Set OneAPI if it's not set by the user if [[ "$@" == *"--use-ipex"* ]] then - if [ -d "$SCRIPT_DIR/venv" ] && [[ -z "${DISABLE_VENV_LIBS}" ]]; then - export LD_LIBRARY_PATH=$(realpath "$SCRIPT_DIR/venv")/lib/:$LD_LIBRARY_PATH + if [[ -z "${DISABLE_VENV_LIBS}" ]]; then + if [ -n "$CONDA_PREFIX" ]; then + export LD_LIBRARY_PATH=$(realpath "$CONDA_PREFIX")/lib/:$LD_LIBRARY_PATH + elif [ -d "$SCRIPT_DIR/venv" ]; then + export LD_LIBRARY_PATH=$(realpath "$SCRIPT_DIR/venv")/lib/:$LD_LIBRARY_PATH + fi fi export NEOReadDebugKeys=1 export ClDeviceGlobalMemSizeAvailablePercent=100