Search code examples
pythonpipenv

Install a python package for all users without messing with the system python installation


I would like to install Pipenv onto a machine so that all users of that machine can use it, but I also don't want to mess with the system Python setup.

I can run sudo pip install pipenv but that goes ahead and changes the version of a bunch of packages installed in the system Python (I am using Scientific Linux 7.4). I would rather keep the system Python exactly as supplied by my linux distro (as I have read that messing with the system Python is a bad idea as core system tools may rely on it being a certain way).

I can do pip install --user pipenv but then only my user can use pipenv.

So two questions:

1. Am I being unnecessarily afraid of modifying the system Python? Is it actually fine to update packages within the system Python?

2. If my caution is justified, what is the best way to pip install things (i.e. tooling such as Pipenv) for all users without modifying the system Python?

I'd ideally like users to just be able to use pipenv by typing pipenv, not having to execute a file located in an obscure directory.

P.S. The ideal situation would be that pipenv was available as a 'safe' package from my distro, but alas it is not. I am also aware of virtualenvs, but my impression those are more for development and deployment of specific projects and not necessarily ideal for system-wide tooling (though I am prepared to be corrected on that).


Solution

  • No, you can never be too afraid of modifying the system Python. Your caution is justified.

    I’d suggest you let all users share a global (but non-system) Python installation, either from the official distribution, Anaconda, pyenv’s python-build, or self-compiled source. Each user can then either perform their own pip install --user to their respective home directories, or you can, as an sudoer, install tools globally available to them, into the custom-managed, non-system, but global Python.


    Edit: I forgot to mention that you may also do this with virtual environments and symlinks. An example for Pipenv (you can change paths as you prefer):

    python3 -m venv /opt/venvs/pipenv
    /opt/venvs/pipenv/bin/pip install pipenv
    ln -s /opt/venvs/pipenv/bin/pipenv /opt/bin/pipenv
    
    python3 -m venv /opt/venvs/flake8
    /opt/venvs/pipenv/bin/pip install flake8
    ln -s /opt/venvs/pipenv/bin/flake8 /opt/bin/flake8
    

    This way to can install multiple tools without them affecting each other. Also you can combine this with custom-managed Python for even more peace of mind.