[Python] What are the differences between `pipx` and `pip --user`?

Discussão em 'Python' iniciado por Stack, Maio 7, 2025.

  1. Stack

    Stack Membro Participativo

    I have tried to install any Python packages on Ubuntu 24.04 (Noble Numbat), but I found I cannot do that as in Ubuntu 22.04 (Jammy Jellyfish).

    PEP 668 said it is for avoiding package conflict between system-wide package and user installed package.

    But what's the differences between using pipx and pip --user? And why does the --user option not work? It also installs packages to the user's own home.

    Example:

    pip install setuptools --user


    Output:

    error: externally-managed-environment

    × This environment is externally managed
    ╰─> To install Python packages system-wide, try apt install
    python3-xyz, where xyz is the package you are trying to
    install.

    If you wish to install a non-Debian-packaged Python package,
    create a virtual environment using python3 -m venv path/to/venv.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
    sure you have python3-full installed.

    If you wish to install a non-Debian packaged Python application,
    it may be easiest to use pipx install xyz, which will manage a
    virtual environment for you. Make sure you have pipx installed.

    See /usr/share/doc/python3.11/README.venv for more information.

    note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
    hint: See PEP 668 for the detailed specification.


    But if I do that with pipx:

    pipx install pip


    Output:

    No apps associated with package pip or its dependencies. If you are attempting to install a library, pipx should not be used. Consider using pip or a similar tool instead.


    I am really confused with current rules.

    How can I manage my user global environment now? And how can I use the latest pip (not Linux distribution version) and other packages by default for current user?

    My environment:

    FROM ubuntu:24.04

    # Add Python
    RUN apt install -y python3-pip python3-venv python-is-python3 pipx

    USER ubuntu
    WORKDIR /app

    Continue reading...

Compartilhe esta Página