From af4c145096d0d9ded35b80558edc03f8aefc5d35 Mon Sep 17 00:00:00 2001 From: Roland Tannous Date: Mon, 16 Feb 2026 04:10:05 +0000 Subject: [PATCH] =?UTF-8?q?setup:=20auto-detect=20best=20Python=20?= =?UTF-8?q?=E2=89=A43.12=20and=20write=20alias=20to=20user's=20default=20s?= =?UTF-8?q?hell=20rc=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup.sh | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 91 insertions(+), 8 deletions(-) diff --git a/setup.sh b/setup.sh index e5a41d371f..bb5da805a8 100755 --- a/setup.sh +++ b/setup.sh @@ -81,7 +81,58 @@ echo "✅ Frontend built to studio/frontend/dist" # ── 6. Python venv + deps ── echo "" echo "Setting up Python environment..." -python3 -m venv .venv + +# ── 6a. Discover best Python <= 3.12.x ── +BEST_PY="" +BEST_MAJOR=0 +BEST_MINOR=0 + +# Collect candidate python3 binaries (python3, python3.9, python3.10, …) +for candidate in $(compgen -c python3 2>/dev/null | grep -E '^python3(\.[0-9]+)?$' | sort -u); do + if ! command -v "$candidate" &>/dev/null; then + continue + fi + # Get version string, e.g. "Python 3.11.5" + ver_str=$("$candidate" --version 2>&1 | awk '{print $2}') + py_major=$(echo "$ver_str" | cut -d. -f1) + py_minor=$(echo "$ver_str" | cut -d. -f2) + + # Skip anything that isn't Python 3 + if [ "$py_major" -ne 3 ] 2>/dev/null; then + continue + fi + + # Skip versions above 3.12 + if [ "$py_minor" -gt 12 ] 2>/dev/null; then + continue + fi + + # Keep the highest qualifying version + if [ "$py_minor" -gt "$BEST_MINOR" ]; then + BEST_PY="$candidate" + BEST_MAJOR="$py_major" + BEST_MINOR="$py_minor" + fi +done + +if [ -z "$BEST_PY" ]; then + echo "❌ ERROR: No Python version <= 3.12.x found on this system." + echo " Detected Python 3 installations:" + for candidate in $(compgen -c python3 2>/dev/null | grep -E '^python3(\.[0-9]+)?$' | sort -u); do + if command -v "$candidate" &>/dev/null; then + echo " - $candidate ($($candidate --version 2>&1))" + fi + done + echo "" + echo " Please install Python <= 3.12.x for maximum compatibility." + echo " For example: sudo apt install python3.12 python3.12-venv" + exit 1 +fi + +BEST_VER=$("$BEST_PY" --version 2>&1 | awk '{print $2}') +echo "✅ Using $BEST_PY ($BEST_VER) — compatible (≤ 3.12.x)" + +"$BEST_PY" -m venv .venv source .venv/bin/activate run_quiet "pip upgrade" pip install --upgrade pip echo " Installing unsloth-zoo + unsloth..." @@ -96,23 +147,55 @@ echo "✅ Python dependencies installed" echo "" REPO_DIR="$SCRIPT_DIR" -if ! grep -qF "unsloth-ui" ~/.bashrc 2>/dev/null; then - cat >> ~/.bashrc </dev/null; then + mkdir -p "$(dirname "$SHELL_RC")" # needed for fish's nested config path + cat >> "$SHELL_RC" <