Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation: Recommend using pipx for installation (PEP 668) #443

Closed
bmunkholm opened this issue Sep 17, 2024 · 5 comments
Closed

Documentation: Recommend using pipx for installation (PEP 668) #443

bmunkholm opened this issue Sep 17, 2024 · 5 comments
Labels
triage An issue that needs to be triaged by a maintainer

Comments

@bmunkholm
Copy link

Documentation feedback


When installing as a python package, should we not recommend using pipx instead of pip to avoid dependency conflicts?

@bmunkholm bmunkholm added the triage An issue that needs to be triaged by a maintainer label Sep 17, 2024
@amotl
Copy link
Member

amotl commented Nov 4, 2024

Dear Brian,

apologies for the late reply, and thanks for your report. Indeed, I only recently became aware that newer distributions of Linux rightfully deny pip acting upon the system Python installation by default, effectively implementing PEP 668 – »Marking Python base environments as “externally managed”«, now the Externally Managed Environments guide.

This procedure succeeded until Debian Bullseye, but fails with Bookworm.

docker run --rm -it debian:bullseye bash
docker run --rm -it debian:bookworm bash
apt-get update
apt-get install --yes python3-pip
pip install crash

With kind regards,
Andreas.

/cc @surister, @simonprickett, @kneth

Error

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.

@amotl
Copy link
Member

amotl commented Nov 4, 2024

OT

If someone reading this, by chance, needs to override this on a system, CI or otherwise ephemeral configuration, or even persistently (don't!), those are two variants, applicable for both the pip and uv package managers.

Disable error: externally-managed-environment by environment variables.

# https://pip.pypa.io/en/stable/cli/pip_install/#cmdoption-break-system-packages
# https://docs.astral.sh/uv/reference/settings/#pip_break-system-packages
PIP_BREAK_SYSTEM_PACKAGES: true
UV_BREAK_SYSTEM_PACKAGES: true

Disable error: externally-managed-environment by configuration.

# https://docs.astral.sh/uv/reference/settings/#pip_break-system-packages
mkdir -p ~/.config/pip
mkdir -p ~/.config/uv
echo -e "[global]\nbreak-system-packages = true" > ~/.config/pip/pip.conf
echo -e "[tool.uv.pip]\nbreak-system-packages = true" > ~/.config/uv/uv.toml

@amotl
Copy link
Member

amotl commented Nov 4, 2024

Solution: Using pipx

@bmunkholm: Thanks for suggesting pipx. Which solution would you prefer to advertise? All of them?

apt-get update
apt-get install --yes pipx
pipx ensurepath
pipx install crash

This command variant would also work, but adds verbosity.

pipx run crash --version

This variant would be sensible for system-wide installation, also using pipx.

export PIPX_BIN_DIR=/usr/local/bin
pipx install crash
crash --version

@amotl amotl changed the title Documentation feedback on /docs/getting-started.rst Documentation: Recommend using pipx for installation Nov 4, 2024
@amotl amotl changed the title Documentation: Recommend using pipx for installation Documentation: Recommend using pipx for installation (PEP 668) Nov 4, 2024
@amotl
Copy link
Member

amotl commented Nov 4, 2024

Solution: Using uv

Another promising installation variant would be to use the uv package manager. That would roughly look like this:

docker run --rm -it debian:bookworm bash
apt-get update && apt-get install --yes curl
curl -LsSf https://astral.sh/uv/install.sh | sh
source $HOME/.cargo/env
uv venv
uv pip install crash
uv run crash --version

Note that uv can also be installed using pip or pipx: pipx install uv. ;]

Note that your system will not even need a Python installation. The first invocation of uv venv will transparently download a Python that will be hosted separately from your system. The roundtrip speed is insane.

Including Python installation

time (uv venv; uv pip install crash; uv run crash --version)
real	0m6.025s
user	0m1.930s
sys	0m1.726s

Excluding Python installation

time (uv venv; uv pip install crash; uv run crash --version)
real	0m1.651s
user	0m1.025s
sys	0m0.265s

NB: Python has been installed beforehand using uv python install 3.13.

@amotl
Copy link
Member

amotl commented Nov 4, 2024

Hi again. GH-451 implements a minimal update to relevant documentation sections, thanks. Feel free to submit any kinds of fixes yourself, we appreciate improvements of any size and matter. 🙏

@amotl amotl closed this as completed Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage An issue that needs to be triaged by a maintainer
Projects
None yet
Development

No branches or pull requests

2 participants