Skip to content

Install Python software into venvs to avoid pip v25+ conflicts#7951

Open
Copilot wants to merge 17 commits intodevfrom
copilot/install-python-software-venvs
Open

Install Python software into venvs to avoid pip v25+ conflicts#7951
Copilot wants to merge 17 commits intodevfrom
copilot/install-python-software-venvs

Conversation

Copy link

Copilot AI commented Feb 17, 2026

Migration Plan: Python Software to Virtual Environments

Analysis Complete

  • Identify all Python software installations in dietpi-software
  • Understand current installation patterns
  • Review special cases and exceptions

Global changes:

  • Remove break-system-packages from /etc/pip.conf
  • Add python3-venv and python3-pip to dependencies
  • Set PYTHON_VERSION as global variable
  • Remove root-user-action=ignore from pip.conf
  • Add --root-user-action=ignore to system pip calls

Software migrated to venv:

  • ID 125: Synapse (Matrix server) - /opt/synapse
  • ID 136: motionEye - /opt/motioneye, sed systemd service (robust pattern)
  • ID 139: SABnzbd - /opt/sabnzbd
  • ID 180: Bazarr - /opt/bazarr/venv
  • ID 155: HTPC Manager - /opt/htpc-manager
  • ID 153: OctoPrint - /mnt/dietpi_userdata/octoprint/venv, owned by octoprint user

Exceptions (kept system install with --break-system-packages):

  • ID 118: Mopidy - APT package, additional modules with --break-system-packages --root-user-action=ignore
  • ID 141: ADS-B Feeder - Uses --break-system-packages --root-user-action=ignore

Already using isolated Python (skipped):

  • ID 157: Home Assistant - Uses pyenv
  • ID 16: microblog.pub - Uses pyenv

Code improvements:

  • Compressed venv creation to single line: [[ -d '/opt/foo' ]] || G_EXEC python3 -m venv --system-site-packages /opt/foo
  • Use global PYTHON_VERSION variable instead of calculating per-software
  • Python_Deps no longer unsets PYTHON_VERSION
  • System pip calls use --root-user-action=ignore flag

All 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:

Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 25.1.1
error: uninstall-no-record-file

× Cannot uninstall pip 25.1.1
╰─> The package's contents are unknown: no RECORD file was found for pip.

hint: The package was installed by Debian. You should check if it can uninstall the package.
[FAILED] DietPi-Software | python3 get-pip.py

Steps to reproduce

  1. Run DietPi-Software on a fresh DietPi install.
  2. Attempt to install Mopidy.
  3. Observe the error above.

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:

  • In https://github.com/MichaIng/DietPi/blob/dev/dietpi/dietpi-software we install a lot of Python software via pip3 and break-system-packages=true as root user into the system-wide /usr/local/lib/python3.x/dist-packages Python site.
  • pip started to require break-system-packages=true for this already since a while, but recently is additionally tries to uninstall distro Python packages installed to /usr/lib/python3/dist-packages before 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.
  • We hence need to move our Python software installation options into virtualenv or venv environments.
  • These venvs should be located below /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.
  • The systemd service would need to load the respective venv, same with the CLI shell alias we generate in some cases.
  • There are some exceptions:
    • OctoPrint is installed on user-level. It needs to become a venv as well, but that venv needs to be owned by the octoprint user, as its GUI allows to install further modules. The venv should be located below /mnt/dietpi_userdata/octoprint as well, since additionally installed modules are treated as user data, rather than fixed execution files which we usually install to /opt/<software name>.
    • ADS-B Feeder and Mopidy are not themselves installed via 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-packages as 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-packages for the particular pip3 call, 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.
    • For motionEye, the motioneye_init command installs a systemd service to /etc/systemd/system/motioneye.conf which calls ExecStart=/usr/local/bin/meyectl. So that service needs to be seded to call the right instance from the venv.
    • Home Assistant and microblog.pub are installed via pyenv into their own isolated Python instances. Hence no venv migration needs to be done for those.
  • As of our coding standard, keep the changes minimal, generate and use the venv with minimal amount of code to just work. Those are not intended as development environments, but as mostly fixed end user environments, which do not change until the software is reinstalled (performing an update), with OctoPrint being one exception.</agent_instructions>

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.

@Joulinar
Copy link
Collaborator

Lets see how copilot is dealing with this 😄

@MichaIng
Copy link
Owner

MichaIng commented Feb 17, 2026

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 get-pip.py or so 😄.

@Joulinar
Copy link
Collaborator

Would we need some migration for existing installations?

Copilot AI changed the title [WIP] Fix Mopidy installation failure in DietPi-Software Install Python software into venvs to avoid pip v25+ conflicts Feb 17, 2026
Copilot AI requested a review from MichaIng February 17, 2026 19:38
@MichaIng
Copy link
Owner

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 /opt/foo exists, it uses /opt/foo/venv, else /opt/foo directly. Also for OctoPrint write access preserved, otherwise following my instructions/hints.

... ah, one mistake: It did remove get-pip.py, as it would indeed also still fail if python3-pip was installed. But python3-pip is not installed. So pip will be currently missing for ADS-B Feeder and Mopidy installs, if I am not mistaken.

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.

Would we need some migration for existing installations?

Yes. We should probably do this on DietPi update to not have all that cleanup code in dietpi-software.

@MichaIng
Copy link
Owner

MichaIng commented Feb 17, 2026

Test installs: https://github.com/MichaIng/DietPi/actions/runs/22114553332

Further tasks:

  • Python_Deps cleanup, as PYTHON_VERSION is now always available
  • Migration in DietPi update:
    • Uninstall system instance of main Python modules
    • Do we want to cleanup /usr/local/lib/python3.x/dist-packages? We would risk to remove modules users installed manually and intentionally. Probably we can ask via dialogue.
    • Migrate environment from OctoPrint into the venv. Need to test whether this is seamlessly possible.
  • Remove --system-site-packages? It is not needed for pip to be available in a venv, as it is added automatically. --system-site-packages can reduce the need of additionally installed modules in the venv, maybe also pip is not fully installed in that case, but a wrapper around system pip or so. But it also means that dependency updates for modules available on system-level are only done if required to satisfy versioned dependency declarations. Not necessarily an issue, but we might want to allow venvs to always use latest available versions (at install time), instead of sticking with possibly outdated system versions of dependencies.

Copilot AI and others added 7 commits February 17, 2026 22:43
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.
@MichaIng MichaIng force-pushed the copilot/install-python-software-venvs branch from 2acb62d to 8e10eb7 Compare February 17, 2026 21:43
@MichaIng
Copy link
Owner

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.
@MichaIng MichaIng force-pushed the copilot/install-python-software-venvs branch from 02e9581 to 47b5289 Compare February 18, 2026 16:31
@MichaIng MichaIng force-pushed the copilot/install-python-software-venvs branch from 47b5289 to fa6ed55 Compare February 18, 2026 16:33
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.
@MichaIng MichaIng marked this pull request as ready for review February 18, 2026 20:27
@MichaIng
Copy link
Owner

Okay, I implemented the migration for Synapse, motionEye, and OctoPrint:

  • Synapse and motionEye were themselves installed via pip, hence the system-site package is uninstalled.
  • OctoPrint was installed into the user-site (which makes no difference regarding pip breakage), as well as plugins installed with its UI. The migration moves the user site to the venv path, and turns that into a venv. It is not 100% straight-forward with python -m venv, since executable wrappers below venv/bin still have the old #!/usr/bin/python3 shebang, so they fail to load any other module. Understanding how this works, without forcing a reinstall of all modules, the shebang is just replaced with the venv/bin/python3 path. This is exactly what a (re)install into the venv does. Works well, all plugins remain available, and new plugins can be installed. OctoPrint recognizes the venv well, like it did recognized the prior user site, to install plugins correctly.

SABnzbd, Bazarr, and HTPC Manager are left untouched. They are installed as source tarball, any only their dependencies installed via pip3 -r requirements.txt. They are not designed for/cannot be installed themselves as Python packages. Since we have no real way to know whether a module at /usr/local/lib/python3.*/dist-packages is a dependency for one of our software options only, and if so for which, we cannot do a cleanup anyway. So no harm to keep software using those. A reinstall will make them use a venv without any additional migration steps needed.

ADS-B Feeder and Mopidy do still require /usr/local/lib/python3.*/dist-packages, though we need to find out whether/how to get rid of it.

Once none of our software options makes any use of /usr/local/lib/python3.*/dist-packages anymore, we can offer a complete uninstall of all packages there, and removal of leftovers.

The adsb-setup.service tries it, which fails due to now missing "--break-system-packages".

Also remove obsolete bash path fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DietPi-Software | Install all Python software options into venvs

3 participants

Comments