mirror of https://github.com/bmaltais/kohya_ss
Merge pull request #3273 from ThanaritKanjanametawatAU/master
Add support for already activated conda environment setuppull/3274/head
commit
e23cd3e7a4
19
gui.sh
19
gui.sh
|
|
@ -42,10 +42,17 @@ SCRIPT_DIR=$(cd -- "$(dirname -- "$0")" && pwd)
|
||||||
# Step into GUI local directory
|
# Step into GUI local directory
|
||||||
cd "$SCRIPT_DIR" || exit 1
|
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
|
source "$SCRIPT_DIR/venv/bin/activate" || exit 1
|
||||||
else
|
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
|
fi
|
||||||
|
|
||||||
# Check if LD_LIBRARY_PATH environment variable exists
|
# Check if LD_LIBRARY_PATH environment variable exists
|
||||||
|
|
@ -87,8 +94,12 @@ fi
|
||||||
#Set OneAPI if it's not set by the user
|
#Set OneAPI if it's not set by the user
|
||||||
if [[ "$@" == *"--use-ipex"* ]]
|
if [[ "$@" == *"--use-ipex"* ]]
|
||||||
then
|
then
|
||||||
if [ -d "$SCRIPT_DIR/venv" ] && [[ -z "${DISABLE_VENV_LIBS}" ]]; then
|
if [[ -z "${DISABLE_VENV_LIBS}" ]]; then
|
||||||
export LD_LIBRARY_PATH=$(realpath "$SCRIPT_DIR/venv")/lib/:$LD_LIBRARY_PATH
|
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
|
fi
|
||||||
export NEOReadDebugKeys=1
|
export NEOReadDebugKeys=1
|
||||||
export ClDeviceGlobalMemSizeAvailablePercent=100
|
export ClDeviceGlobalMemSizeAvailablePercent=100
|
||||||
|
|
|
||||||
27
setup.sh
27
setup.sh
|
|
@ -192,18 +192,24 @@ install_python_dependencies() {
|
||||||
# Switch to local virtual env
|
# Switch to local virtual env
|
||||||
echo "Switching to virtual Python environment."
|
echo "Switching to virtual Python environment."
|
||||||
if ! inDocker; then
|
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"
|
python3.10 -m venv "$DIR/venv"
|
||||||
|
# Activate the virtual environment
|
||||||
|
source "$DIR/venv/bin/activate"
|
||||||
elif command -v python3 >/dev/null; then
|
elif command -v python3 >/dev/null; then
|
||||||
python3 -m venv "$DIR/venv"
|
python3 -m venv "$DIR/venv"
|
||||||
|
# Activate the virtual environment
|
||||||
|
source "$DIR/venv/bin/activate"
|
||||||
else
|
else
|
||||||
echo "Valid python3 or python3.10 binary not found."
|
echo "Valid python3 or python3.10 binary not found."
|
||||||
echo "Cannot proceed with the python steps."
|
echo "Cannot proceed with the python steps."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Activate the virtual environment
|
|
||||||
source "$DIR/venv/bin/activate"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case "$OSTYPE" in
|
case "$OSTYPE" in
|
||||||
|
|
@ -228,11 +234,16 @@ install_python_dependencies() {
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [ -n "$VIRTUAL_ENV" ] && ! inDocker; then
|
if [ -n "$VIRTUAL_ENV" ] && ! inDocker; then
|
||||||
if command -v deactivate >/dev/null; then
|
# Don't deactivate if we're using a conda environment that was already active
|
||||||
echo "Exiting Python virtual environment."
|
if [ -z "$CONDA_PREFIX" ] || [ "$VIRTUAL_ENV" != "$CONDA_PREFIX" ]; then
|
||||||
deactivate
|
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
|
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
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue