Merge pull request #3273 from ThanaritKanjanametawatAU/master

Add support for already activated conda environment setup
pull/3274/head
bmaltais 2025-06-05 14:56:56 -04:00 committed by GitHub
commit e23cd3e7a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 12 deletions

17
gui.sh
View File

@ -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,9 +94,13 @@ 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
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
if [[ ! -z "${IPEXRUN}" ]] && [ ${IPEXRUN}="True" ] && [ -x "$(command -v ipexrun)" ]

View File

@ -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,12 +234,17 @@ install_python_dependencies() {
esac
if [ -n "$VIRTUAL_ENV" ] && ! inDocker; then
# 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 "Keeping conda environment active as it was already activated before running this script."
fi
fi
}