Prefer /usr/bin/python3 over PATH uv-managed interpreters

setup_linux.sh used command -v python3, which with an activated .venv or
uv on PATH resolved to ~/.local/share/uv/python/... and failed the gi
preflight even though apt python3-gi was installed. Always use
/usr/bin/python3 for the native-window venv.

Co-authored-by: Diaco Soltanpour <s-diaco@users.noreply.github.com>
This commit is contained in:
Cursor Agent
2026-07-25 06:03:16 +00:00
parent c38d9a93be
commit 3463fb74df
4 changed files with 41 additions and 16 deletions

View File

@@ -31,10 +31,11 @@ Select with `--backend com|ooxml` (CLI) or the Backend dropdown (web UI).
not installable with `uv`. Prefer `./desktop/setup_linux.sh`, which recreates
`.venv` with **OS** `/usr/bin/python3` (`--no-managed-python --system-site-packages`).
A uv-managed CPython (e.g. from `~/.local/share/uv/python`) cannot load apt
`_gi` even with system-site-packages. `.python-version` is `3.12` (minor pin,
not `3.12.2`) so sync can use OS `/usr/bin/python3`. On this headless/cloud VM
native mode is often unavailable; the app falls back to the browser, or use
`--no-browser` / `--browser`.
`_gi` even with system-site-packages. `setup_linux.sh` always uses
`/usr/bin/python3`, not PATH `python3`. `.python-version` is `3.12` (minor pin)
so sync can use the OS interpreter. On this headless/cloud VM native mode is
often unavailable; the app falls back to the browser, or use `--no-browser`
/ `--browser`.
### Environment
- Prefer **uv** for all installs (`uv` in `~/.local/bin`, on PATH via `~/.bashrc`).

View File

@@ -76,10 +76,11 @@ chmod +x desktop/setup_linux.sh
./desktop/setup_linux.sh
```
That installs apt GTK/WebKit packages if needed, recreates `.venv` with the
**OS** `/usr/bin/python3` (`--no-managed-python --system-site-packages` so apt
That installs apt GTK/WebKit packages if needed, recreates `.venv` with
**`/usr/bin/python3`** (`--no-managed-python --system-site-packages` so apt
`python3-gi` / `_gi` loads), runs `uv sync`, and creates a Desktop shortcut.
Do not use a uv-managed CPython for the Linux native window — `_gi` will fail.
It ignores PATH `python3` when that points at a uv-managed build under
`~/.local/share/uv/python/` (common with an activated `.venv`).
**Manual / macOS** (deps only; on Linux this alone is not enough for a native window):

View File

@@ -30,17 +30,39 @@ if ! command -v uv >/dev/null 2>&1; then
exit 1
fi
if ! command -v python3 >/dev/null 2>&1; then
echo "python3 not found on PATH." >&2
# Must use the OS interpreter that apt's python3-gi/_gi was built for.
# Never use `command -v python3`: with an activated .venv or uv on PATH it often
# resolves to ~/.local/share/uv/python/... which cannot import apt gi.
resolve_os_python() {
local candidate resolved
for candidate in /usr/bin/python3 /usr/local/bin/python3; do
if [[ -x "$candidate" ]]; then
resolved="$(readlink -f "$candidate")"
# Reject uv-managed installs even if somehow symlinked here.
if [[ "$resolved" == *"/uv/python/"* ]] || [[ "$resolved" == *".local/share/uv/"* ]]; then
continue
fi
printf '%s\n' "$resolved"
return 0
fi
done
return 1
}
if ! SYSTEM_PYTHON="$(resolve_os_python)"; then
echo "OS Python not found at /usr/bin/python3." >&2
echo "Install python3 from apt, then re-run. Do not rely on uv-managed Python." >&2
exit 1
fi
# Must use the OS interpreter that apt's python3-gi/_gi was built for.
# Plain `uv venv --python python3` often picks a uv-managed CPython that cannot
# load system _gi (partially initialized module / cannot import name '_gi').
SYSTEM_PYTHON="$(readlink -f "$(command -v python3)")"
SYSTEM_VERSION="$("$SYSTEM_PYTHON" -c 'import sys; print(sys.version.split()[0])')"
echo "Using system Python: ${SYSTEM_PYTHON} (${SYSTEM_VERSION})"
echo "Using OS Python: ${SYSTEM_PYTHON} (${SYSTEM_VERSION})"
if PATH_PYTHON="$(command -v python3 2>/dev/null || true)"; then
PATH_PYTHON_RESOLVED="$(readlink -f "$PATH_PYTHON" 2>/dev/null || true)"
if [[ -n "$PATH_PYTHON_RESOLVED" && "$PATH_PYTHON_RESOLVED" != "$SYSTEM_PYTHON" ]]; then
echo "Note: PATH python3 is ${PATH_PYTHON_RESOLVED} (ignored; apt gi needs OS Python)."
fi
fi
echo "Preflight: system Python must import Gtk/WebKit..."
if ! "$SYSTEM_PYTHON" - <<'PY'

View File

@@ -39,8 +39,9 @@ def _linux_native_hint(detail: str | None = None) -> str:
if "_gi" in detail_l or "partially initialized" in detail_l:
lines.append(
"This usually means the venv Python does not match apt "
"python3-gi (uv picked a managed CPython). Re-run "
"./desktop/setup_linux.sh so .venv uses /usr/bin/python3."
"python3-gi (uv-managed CPython on PATH, e.g. "
"~/.local/share/uv/python/...). Re-run ./desktop/setup_linux.sh "
"so .venv uses /usr/bin/python3 (not PATH python3)."
)
lines.append(
"Falling back to the default browser. "