Skip to content

Commit c116abd

Browse files
committed
Improve Python version handling in Linux installer
1 parent 23f0abd commit c116abd

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

docs/linux-raspberry-pi.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ sudo apt update
2020
sudo apt install -y git python3 python3-venv python3-pip rsync
2121
```
2222

23+
APRS PropView requires Python 3.11 or newer. Raspberry Pi OS / Debian 11
24+
(bullseye) commonly installs Python 3.9 as `python3`; use a newer Python by
25+
setting `PYTHON_BIN` when running the installer, or upgrade to an OS release
26+
that provides Python 3.11+.
27+
2328
## Get The Source
2429

2530
```bash
@@ -91,6 +96,16 @@ To install for a specific Linux user:
9196
sudo APRS_PROPVIEW_USER=pi bash ./scripts/install_linux.sh
9297
```
9398

99+
To install with a specific Python 3.11+ interpreter:
100+
101+
```bash
102+
sudo PYTHON_BIN=/path/to/python3.11 bash ./scripts/install_linux.sh
103+
```
104+
105+
Set `PYTHON_BIN` on the same `sudo` command line as shown above. Running
106+
`export PYTHON_BIN=/path/to/python3.11` before `sudo bash ...` may not work
107+
because many systems do not preserve user environment variables through `sudo`.
108+
94109
To choose a different install directory or service name:
95110

96111
```bash

scripts/install_linux.sh

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,31 @@ if [[ "${EUID}" -ne 0 ]]; then
1818
fi
1919

2020
if ! command -v "${PYTHON_BIN}" >/dev/null 2>&1; then
21-
echo "Missing ${PYTHON_BIN}. Install python3 and python3-venv, then run this script again." >&2
21+
echo "Missing ${PYTHON_BIN}. Install Python 3.11+ and the matching venv package, then run this script again." >&2
22+
exit 1
23+
fi
24+
25+
PYTHON_VERSION="$("${PYTHON_BIN}" - <<'PY'
26+
import sys
27+
print(f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}")
28+
PY
29+
)"
30+
31+
if ! "${PYTHON_BIN}" - <<'PY'
32+
import sys
33+
raise SystemExit(0 if sys.version_info >= (3, 11) else 1)
34+
PY
35+
then
36+
cat >&2 <<EOF
37+
${PYTHON_BIN} is Python ${PYTHON_VERSION}, but APRS PropView requires Python 3.11 or newer.
38+
39+
Raspberry Pi OS / Debian 11 (bullseye) commonly provides Python 3.9 as
40+
python3. Install a newer Python and rerun this installer with:
41+
42+
sudo PYTHON_BIN=/path/to/python3.11 bash ./scripts/install_linux.sh
43+
44+
Or upgrade to an OS release that provides Python 3.11+.
45+
EOF
2246
exit 1
2347
fi
2448

@@ -75,6 +99,22 @@ fi
7599

76100
chown -R "${RUN_USER}:${RUN_USER}" "${INSTALL_DIR}"
77101

102+
if [[ -x "${INSTALL_DIR}/.venv/bin/python" ]]; then
103+
VENV_VERSION="$("${INSTALL_DIR}/.venv/bin/python" - <<'PY'
104+
import sys
105+
print(f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}")
106+
PY
107+
)"
108+
if ! "${INSTALL_DIR}/.venv/bin/python" - <<'PY'
109+
import sys
110+
raise SystemExit(0 if sys.version_info >= (3, 11) else 1)
111+
PY
112+
then
113+
echo "Existing virtualenv uses Python ${VENV_VERSION}; recreating it with ${PYTHON_BIN}."
114+
rm -rf "${INSTALL_DIR}/.venv"
115+
fi
116+
fi
117+
78118
sudo -u "${RUN_USER}" "${PYTHON_BIN}" -m venv "${INSTALL_DIR}/.venv"
79119
sudo -u "${RUN_USER}" "${INSTALL_DIR}/.venv/bin/python" -m pip install --upgrade pip
80120
sudo -u "${RUN_USER}" "${INSTALL_DIR}/.venv/bin/python" -m pip install -r "${INSTALL_DIR}/requirements.txt"

0 commit comments

Comments
 (0)