pythonpython-3.xpipdebian

What should I do with --user installed packages on Debian? (in light of PEP668)


In light of some distributions (Debian at least) steering away from

python3 -m pip install numpy

what should I do with my user packages that I had installed with python3 -m pip install --user numpy (for instance)?

They are located in python3 -m site --user-site : ~/.local/lib/python3.11/site-packages/.

I don't want to:

  1. delete /usr/lib/python3.x/EXTERNALLY-MANAGED
  2. install pipx
  3. sometimes, of course, cannot find an apt managed package

I'm all for using venv, but do I make some ~/.local/lib/python3/packages folder and include it in a PYTHON_PATH, but also make that folder a venv virtual environment? Should I move what is in my ~/.local/lib/python3.11/site-packages/ folder to this new folder, or re-download?

For someone who uses Python and 'standard' packages, I really don't need to worry about mixing things too much, but to me it seems (only for me as a low-key user) that functionally there is little difference between venv installs in one directory (one for each project) and --user installs in another.

I've looked around a lot about this but couldn't find a "here's what to do" tutorial on adopting the change. Or maybe I am missing some big picture...

How do I solve "error: externally-managed-environment" everytime I use pip3?

pip install -r requirements.txt is failing: "This environment is externally managed"

pip install -r requirements.txt is failing: "This environment is externally managed"


Solution

  • I decided to use pipenv to manage my packages, but to install it, I have to do a pip install. I wanted to do this just for my user, so I created a local venv for it,

    mkdir -p ~/.local/share/
    apt install python3-pip
    python3 -m venv ~/.local/share/pipenv
    source ~/.local/share/pipenv/bin/activate
    

    and installed pipenv on it:

    pip install pipenv
    

    To now use pipenv with my user, I added the path to the pipenv bin venv to my PATH:

    export PATH=$HOME/.local/share/pipenv/bin:$PATH
    

    Now I can use pipenv to manage the project venvs. It's kinda convoluted, I know, but Python can be quite convoluted with packages.