From db484ce0d0132427db34dac091eee31e85b45d39 Mon Sep 17 00:00:00 2001 From: master3395 Date: Wed, 4 Feb 2026 21:47:38 +0100 Subject: [PATCH] Fix makemigrations FileNotFoundError: skip broken venv symlinks when choosing Python - Resolve symlinks and require executable file before using a path - Skip paths that are broken symlinks or not executable (e.g. /usr/local/CyberPanel -> CyberCP when venv missing) - Catch FileNotFoundError/OSError from subprocess when testing --version - Ensures system python3 is used when venv paths are invalid --- install/install.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/install/install.py b/install/install.py index 9bdae4b48..7d6ab6a03 100644 --- a/install/install.py +++ b/install/install.py @@ -3367,7 +3367,8 @@ password="%s" if not self.ensureVirtualEnvironmentSetup(): logging.InstallLog.writeToFile("WARNING: No venv found; will try system Python", 1) - # Find Python: prefer venv, then system python3 (avoids FileNotFoundError for /usr/local/CyberPanel/bin/python) + # Find Python: prefer venv, then system python3 (avoid FileNotFoundError for broken /usr/local/CyberPanel/bin/python) + # Check resolved path so broken symlinks are skipped python_paths = [ "/usr/local/CyberCP/bin/python", "/usr/local/CyberPanel/bin/python", @@ -3380,15 +3381,26 @@ password="%s" python_path = None for path in python_paths: - if path and os.path.exists(path): - try: - r = subprocess.run([path, "--version"], capture_output=True, text=True, timeout=5) - if r.returncode == 0: - python_path = path - logging.InstallLog.writeToFile(f"Using Python at: {path}") - break - except Exception: + if not path: + continue + try: + # Skip broken symlinks: resolve and require executable file + if os.path.lexists(path): + resolved = os.path.realpath(path) + if not os.path.isfile(resolved) or not os.access(resolved, os.X_OK): + continue + elif not os.path.isfile(path) or not os.access(path, os.X_OK): continue + except OSError: + continue + try: + r = subprocess.run([path, "--version"], capture_output=True, text=True, timeout=5) + if r.returncode == 0: + python_path = path + logging.InstallLog.writeToFile(f"Using Python at: {path}") + break + except (FileNotFoundError, OSError, subprocess.SubprocessError): + continue if not python_path: logging.InstallLog.writeToFile("ERROR: No working Python found for migrations!", 0)