pato-pan 6aba5ad177
Update run.sh
pyenv only checks for python version in the current directory now. The working directory will now always be the one where the script is located (in case you run it outside the folder, example: `./RVC/run.sh`) this also makes it so pyenv will always only show the version that applies to the current folder.

I considered this alternative before coming up with this, "-qvE "3.8|`dirname -- $(readlink -fn -- "$0")`"", but this is longer and more complicated, and has the same requirements, so I discarded it. Sharing it in case someone else finds it useful
2024-07-18 19:06:56 -04:00

70 lines
2.0 KiB
Bash
Executable File

#!/bin/sh
# Changes the working directory to the one where the bash script is located.
cd $(dirname -- $(readlink -fn -- "$0"))
if [ "$(uname)" = "Darwin" ]; then
# macOS specific env:
export PYTORCH_ENABLE_MPS_FALLBACK=1
export PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0
elif [ "$(uname)" != "Linux" ]; then
echo "Unsupported operating system."
exit 1
fi
if [ -d ".venv" ]; then
echo "Activate venv..."
. .venv/bin/activate
else
echo "Create venv..."
requirements_file="requirements.txt"
# Check if Python 3.8 is installed
if ! command -v python3.8 >/dev/null 2>&1 || pyenv version --bare | grep -qv "3.8"; then
echo "Python 3 not found. Attempting to install 3.8..."
if [ "$(uname)" = "Darwin" ] && command -v brew >/dev/null 2>&1; then
brew install python@3.8
elif [ "$(uname)" = "Linux" ] && command -v apt-get >/dev/null 2>&1; then
sudo apt-get update
sudo apt-get install python3.8
elif [ "$(uname)" = "Linux" ] && command -v pyenv >/dev/null 2>&1; then
pyenv install 3.8
pyenv local 3.8
alias python3.8=python
else
echo "Please install Python 3.8 manually."
exit 1
fi
fi
python3.8 -m venv .venv
. .venv/bin/activate
# Check if required packages are installed and install them if not
if [ -f "${requirements_file}" ]; then
installed_packages=$(python3.8 -m pip freeze)
while IFS= read -r package; do
expr "${package}" : "^#.*" > /dev/null && continue
package_name=$(echo "${package}" | sed 's/[<>=!].*//')
if ! echo "${installed_packages}" | grep -q "${package_name}"; then
echo "${package_name} not found. Attempting to install..."
python3.8 -m pip install --upgrade "${package}"
fi
done < "${requirements_file}"
else
echo "${requirements_file} not found. Please ensure the requirements file with required packages exists."
exit 1
fi
fi
# Download models
chmod +x tools/dlmodels.sh
./tools/dlmodels.sh
if [ $? -ne 0 ]; then
exit 1
fi
# Run the main script
python3.8 infer-web.py --pycmd python3.8