From 73ec412273f7190e655c41e9e63f42b531bcbd9d Mon Sep 17 00:00:00 2001 From: Vidalnt Date: Sat, 7 Sep 2024 23:05:39 -0500 Subject: [PATCH] Fix --- run-applio.sh | 53 ++++----------------------------------------------- setup-venv.sh | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 49 deletions(-) create mode 100644 setup-venv.sh diff --git a/run-applio.sh b/run-applio.sh index f4ca11582..f4bd501e0 100644 --- a/run-applio.sh +++ b/run-applio.sh @@ -1,54 +1,9 @@ #!/bin/sh printf "\033]0;Applio\007" - -if ! dpkg -s python3.10-venv > /dev/null 2>&1; then - echo "Installing python3.10-venv..." - sudo apt-get update - sudo apt-get install -y python3.10-venv -fi - -if ! command -v python > /dev/null 2>&1 && ! command -v python3 > /dev/null 2>&1; then - echo "Error: Python or Python 3 not found. Please install one of them." - exit 1 -fi - -if [ ! -d ".venv" ]; then - echo "Error: Virtual environment not found. Please run the installer first." - exit 1 -fi - -echo "Checking if python exists" -if command -v python3.10 > /dev/null 2>&1; then - PYTHON_EXECUTABLE=$(which python3.10) - echo "Using python3.10" -elif command -v python3 > /dev/null 2>&1; then - PYTHON_EXECUTABLE=$(which python3) - echo "Using python3" -elif command -v python > /dev/null 2>&1; then - PYTHON_EXECUTABLE=$(which python) - echo "Using python" -else - echo "Error: Unable to find a suitable Python version." - exit 1 -fi - -PYTHON_HOME=$(dirname "$PYTHON_EXECUTABLE") - -CURRENT_HOME=$(grep "^home =" .venv/pyvenv.cfg | cut -d "=" -f 2 | xargs) - -if [ "$CURRENT_HOME" != "$PYTHON_HOME" ]; then - sed -i "s|home =.*|home = $PYTHON_HOME|" .venv/pyvenv.cfg - VENV_PATH=$(realpath .venv) - find "$VENV_PATH/bin/" -type f -exec sed -i "0,/^VIRTUAL_ENV=/s|VIRTUAL_ENV=.*|VIRTUAL_ENV='$VENV_PATH'|" {} \; -else - echo "Home path in .venv/pyvenv.cfg is already up-to-date" -fi - . .venv/bin/activate -export PYTORCH_ENABLE_MPS_FALLBACK=1 -export PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0 - + export PYTORCH_ENABLE_MPS_FALLBACK=1 + export PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0 + clear - -"$PYTHON_EXECUTABLE" app.py --open +python app.py --open diff --git a/setup-venv.sh b/setup-venv.sh new file mode 100644 index 000000000..e17ef9707 --- /dev/null +++ b/setup-venv.sh @@ -0,0 +1,50 @@ +#!/bin/sh +printf "\033]0;Applio\007" + +if ! dpkg -s python3.10-venv > /dev/null 2>&1; then + echo "Installing python3.10-venv..." + sudo apt-get update + sudo apt-get install -y python3.10-venv +fi + +if ! command -v python > /dev/null 2>&1 && ! command -v python3 > /dev/null 2>&1; then + echo "Error: Python or Python 3 not found. Please install one of them." + exit 1 +fi + +if [ ! -d ".venv" ]; then + echo "Error: Virtual environment not found. Please run the installer first." + exit 1 +fi + +venv_dir=".venv" + +if command -v python3.10 > /dev/null 2>&1; then + python_exe=$(which python3.10) + echo "Using python3.10" +elif command -v python3 > /dev/null 2>&1; then + python_exe=$(which python3) + echo "Using python3" +elif command -v python > /dev/null 2>&1; then + python_exe=$(which python) + echo "Using python" +else + echo "Error: Unable to find a suitable Python version." + exit 1 +fi + +python_home=$(dirname "$python_exe") +python_prefix=$(dirname "$python_home") +python_exec_prefix="$python_prefix" + +sed -i 's/\r$//' "$venv_dir/pyvenv.cfg" +sed -i "s|^home =.*|home = $python_home|" "$venv_dir/pyvenv.cfg" +sed -i "s|^base-prefix =.*|base-prefix = $python_prefix|" "$venv_dir/pyvenv.cfg" +sed -i "s|^base-exec-prefix =.*|base-exec-prefix = $python_exec_prefix|" "$venv_dir/pyvenv.cfg" +sed -i "s|^base-executable =.*|base-executable = $python_exe|" "$venv_dir/pyvenv.cfg" + +current_dir=$(pwd) + +find "$venv_dir" -type f -exec sed -i -e 's/\r$//' -e "s|/home/runner/work/Applio/Applio/|$current_dir/|g" -e "s|/.venv/bin/python|/.venv/bin/$(basename $python_exe)|g" {} + + +echo "Virtual environment paths fixed." \ No newline at end of file