Install Python deps via apt so the root service can import them (#74) - #75
Open
cuneytozseker wants to merge 1 commit into
Open
Install Python deps via apt so the root service can import them (#74)#75cuneytozseker wants to merge 1 commit into
cuneytozseker wants to merge 1 commit into
Conversation
setup.sh installed requests, flask and python-dotenv with `pip3 --user`, which lands in the invoking user's ~/.local. tinyprogrammer.service runs as root, whose sys.path never includes that directory, so main.py died with "No module named flask" and systemd restart-looped it every 5s. pygame and PIL were unaffected only because they already came from apt. Move all of them to apt so everything is installed system-wide, and add an explicit root import check in place of the pip step — the service user is the one that has to resolve these, so that is the user to test. Also add python3-numpy, which was never installed at all despite display/framebuffer.py importing it at module level on the Pi render path. It resolved until now only as a transitive dependency of python3-pygame. Reported-by: krs-novice Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018hU2w7FyVR7WDegE8sWeAM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #74.
The bug
TinyProgrammer does not run out of the box on a fresh Pi install.
setup.shinstalled three of its Python dependencies as the invoking (unprivileged) user:On Bookworm that lands in
~/<user>/.local/lib/python3.11/site-packages. Buttinyprogrammer.servicesetsUser=rootand runs/usr/bin/python3 .../main.py, and root'ssys.pathincludes/root/.local/...— never the installing user's. Soimport flaskfails and the app never starts.pygameandPILwere unaffected only because they already came fromaptin the same script and are therefore installed system-wide. That is exactly whyflaskis the module people see in the log.Because the unit sets
Restart=on-failurewithRestartSec=5, this doesn't fail once and stop — it crash-loops every five seconds, which reads as a display problem unless you happen to check/var/log/tinyprogrammer.log.The fix
Move all of the Python dependencies to
aptso everything is installed system-wide and root can resolve it. This keepsUser=rootand the framebuffer assumptions in the service unit unchanged, and drops the--break-system-packagesworkaround entirely.In place of the pip step,
setup.shnow verifies the imports as root — the same user the service runs as, so this class of bug cannot ship silently again:sudo python3 -c 'import pygame, PIL, numpy, flask, requests, dotenv'Also: python3-numpy was never installed
While scoping this I found a second gap.
setup.shnever installed numpy at all, and neither did the README's manual instructions — it is inrequirements.txt, butsetup.shhand-lists packages rather than reading that file.display/framebuffer.py:13imports numpy at module level, on the core Pi render path (rgb888_to_rgb565,rgb888_to_xrgb8888), as doesdisplay/color_adjustment.py:8whichframebuffer.pyimports. A missing numpy is a startup crash, not a degraded feature.It has been resolving until now only as a transitive dependency of
python3-pygame. That is accidental, sopython3-numpyis now requested explicitly.Alternative considered
@krs-novice's own fix — keeping
User=rootand dropping to the user formain.pyviarunuser— also works, and is more careful than it first appears: it leaves the twoExecStartPrelines running as root, and the first of those (echo 0 > /sys/class/graphics/fbcon/cursor_blink) has no-prefix, so it would fail the whole unit if it couldn't write. A plain switch toUser=<user>would break that and would additionally need the user in thevideogroup for/dev/fb0.I went the apt route because it is the smaller diff and leaves the documented root/framebuffer model intact.
Testing
bash -n setup.shpasses. Not yet verified on hardware — this needs one run on a Pi to confirm the apt package names resolve and the check passes:apt-cache policy python3-flask python3-requests python3-dotenv python3-numpy sudo python3 -c 'import pygame, PIL, numpy, flask, requests, dotenv'Reported by @krs-novice in #74.
Generated with Claude Code
https://claude.ai/code/session_018hU2w7FyVR7WDegE8sWeAM