Module installation for multiple users

I’m running a small server and am using python for multiple purposes, among others for a CGI script running with apache2 (I’m working on replacing CGI with flask, but that’s not the topic here). I installed modules that were not available as Debian packages with pip. After updating Debian to Bookworm this is no longer supported/recommended and now all these packages are missing.

As I’m trying to run everything with least privileges and as separated from each other as possible there are multiple users which run python programs that need the same packages. The standard way of using a venv per user seems quite complicated as all these users should have access to all modules I install.

Is there a better way than installing the same module multiple times and having to update the same module manually multiple times? E.g. is it possible to set up a global virtual environment (administered by root) and use this with multiple users?

Certainly. Make a place for it eg /opt/venv, create that as root. Then
chown it to an admin user (make a new one, eg venv_admin). Log in
(su or sudo etc) as that user and run its pip command or its
python -m pip to do the package installs.


 root# python3 -m venv /opt/venv
 root# chown venv_admin:venv_admin /opt/venv
 root# su - venv_admin
 venv_admin$ /opt/venv/bin/python3 -m pip install -U pip wheel
 venv_admin$ /opt/venv/bin/python3 -m pip install ...whatever...

Scripts working from this venv can use this as their shebang:


or rig their environment with /opt/venv/bin at the start of $PATH.

Admining the venv as a dedicated user has the advantage of not running
any module install stuff as root.

Cameron Simpson

1 Like