Install Python software into venvs to avoid pip v25+ conflicts#7951
Install Python software into venvs to avoid pip v25+ conflicts#7951
Conversation
|
Lets see how copilot is dealing with this 😄 |
|
From the initial comments and title it misinterpreted the issue. I changed the issue title and added clarification, also explicitly via agent instructions, before assigning Copilot to the issue, so I hope it gets things right after reading those and does not remove |
|
Would we need some migration for existing installations? |
|
Hah, it did get it right. Impressive, isn't it? First commit pretty flawless. I'll do some format changes, but so far did not see a mistake which would not work. Also, where ... ah, one mistake: It did remove Also nice to see the iterations it does, adding uninstall adjustments afterwards (I did not mention this anywhere, I just got the idea), code hardening.
Yes. We should probably do this on DietPi update to not have all that cleanup code in |
|
Test installs: https://github.com/MichaIng/DietPi/actions/runs/22114553332 Further tasks:
|
Co-authored-by: MichaIng <28480705+MichaIng@users.noreply.github.com>
Co-authored-by: MichaIng <28480705+MichaIng@users.noreply.github.com>
Co-authored-by: MichaIng <28480705+MichaIng@users.noreply.github.com>
…pip, compress venv creation Co-authored-by: MichaIng <28480705+MichaIng@users.noreply.github.com>
…ON in Python_Deps Python_Deps changes the format of the variable, but it must not change the global PYTHON_VERSION format. Check and error out if PYTHON_VERSION is not set.
2acb62d to
8e10eb7
Compare
Latest piwheels Python 3.13 pillow build failed. Remove Python 3.9 checks.
|
venv adds pip automatically, so it is not needed on system-level. Instead, install it only for the two cases where we do install further packages on system-level. Always run "python3 -m venv" even if the venv directory exists already. It might repair or refresh the venv. Add "--upgrade-deps" to upgrade pip to latest version. Bazarr: Move venv out of /opt/bazarr. That way it is preserved on reinstalls, and Bazarr does not get write access to the venv itself. It has an intenal update which might mess with unexpected files inside /opt/bazarr. HTPC Manager: minor code enhancement LazyLibrarian: remove system-level pip dependency, and venv generation and use python3 and pip3. There is still the theoretial possibility that people install Python 2 or some Python 4 in the future into that venv. Be failsafe and always use Python 3 instances explicitly. When uninstalling system-level packages via pip, pass "--break-system-packages --root-user-action=ignore" as well.
02e9581 to
47b5289
Compare
47b5289 to
fa6ed55
Compare
This is only done where the actual end user software itself was installed via pip. In all other cases, only dependencies were installed via pip, and there is no point to perform the migration now: we have no way to cleanup the system-site, since we cannot know which package was installed as dependency for our software options only, and which are needed for other software, possibly installed by the admin. We cannot offer a complete removal of `/usr/local/lib/python3.*/dist-packages` either, since Mopidy and ADS-B Feeder at least still require it. Once this is not the case anymore, we can offer to uninstall all packages form that site, in favour of consequent venv (or similar) usage, as modern pip makes it increasingly hard to install packages via pip on system-level, while `python3-*` modules can be installed via APT.
|
Okay, I implemented the migration for Synapse, motionEye, and OctoPrint:
SABnzbd, Bazarr, and HTPC Manager are left untouched. They are installed as source tarball, any only their dependencies installed via ADS-B Feeder and Mopidy do still require Once none of our software options makes any use of |
The adsb-setup.service tries it, which fails due to now missing "--break-system-packages". Also remove obsolete bash path fix.
Migration Plan: Python Software to Virtual Environments
Analysis Complete
Global changes:
break-system-packagesfrom/etc/pip.confpython3-venvandpython3-pipto dependenciesPYTHON_VERSIONas global variableroot-user-action=ignorefrom pip.conf--root-user-action=ignoreto system pip callsSoftware migrated to venv:
/opt/synapse/opt/motioneye, sed systemd service (robust pattern)/opt/sabnzbd/opt/bazarr/venv/opt/htpc-manager/mnt/dietpi_userdata/octoprint/venv, owned by octoprint userExceptions (kept system install with --break-system-packages):
--break-system-packages --root-user-action=ignore--break-system-packages --root-user-action=ignoreAlready using isolated Python (skipped):
Code improvements:
[[ -d '/opt/foo' ]] || G_EXEC python3 -m venv --system-site-packages /opt/fooPYTHON_VERSIONvariable instead of calculating per-softwarePYTHON_VERSION--root-user-action=ignoreflagAll tasks completed! ✅
Original prompt
This section details on the original issue you should resolve
<issue_title>DietPi-Software | Install all Python software options into venvs</issue_title>
<issue_description>### Describe the bug
When installing Mopidy via DietPi-Software, the installation fails with an error related to pip:
Steps to reproduce
Expected behavior
Mopidy should install correctly without attempting to uninstall the system pip package, respecting the Debian-provided pip installation.
Actual behavior
DietPi attempts to uninstall the system pip using get-pip.py, which fails because Debian pip has no RECORD file.
System information
DietPi version: latest
Reference code: 27b12307-94fd-435d-a727-00f0f85c2fab
The issue seems related to DietPi calling get-pip.py unnecessarily when pip is already installed via Debian packages.</issue_description>
<agent_instructions>I leave here some info and instructions for this task:
pip3andbreak-system-packages=trueas root user into the system-wide/usr/local/lib/python3.x/dist-packagesPython site.pipstarted to requirebreak-system-packages=truefor this already since a while, but recently is additionally tries to uninstall distro Python packages installed to/usr/lib/python3/dist-packagesbefore installing modules with the same name to/usr/local/lib/python3.x/dist-packages. And this uninstall attempt fails, as can be seen in OP./opt/<software name>or directly at/opt/<software name>if not otherwise used. If the directory exists already, it could be checked whether the venv is still for the right Python version, else it would need to be recreated.octoprintuser, as its GUI allows to install further modules. The venv should be located below/mnt/dietpi_userdata/octoprintas well, since additionally installed modules are treated as user data, rather than fixed execution files which we usually install to/opt/<software name>.pip, but we install additional Python modules for them to use. We do not control the system services for those two software titles, and especially Mopidy is itself installed to/usr/lib/python3/dist-packagesas APT package, hence, AFAIK, cannot load modules additionally from a venv. So we need to keep installing the additional modules to the system site. But is is probably okay to do this via explicit--break-system-packagesfor the particularpip3call, rather than setting this flag in/etc/pip.conf. We need to check back with upstream developers about how to solve it best in those two cases.motioneye_initcommand installs a systemd service to/etc/systemd/system/motioneye.confwhich callsExecStart=/usr/local/bin/meyectl. So that service needs to beseded to call the right instance from the venv.pyenvinto their own isolated Python instances. Hence no venv migration needs to be done for those.Comments on the Issue (you are @copilot in this section)
@MichaIng For now, uninstall the APT package: ```sh apt autopurge python3-pip ``` Switching all Python software options to venv's is planned for DietPi v10.0 in January, or maybe v10.1 in February. I hope there is a way to install `pip` and e.g. `setuptools` into the venv directly, to basically not have any system instance anymore that could conflict with Debian packages. @MichaIng The ones you selected for this run, yes. If `dietpi-software` aborts i...✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.