uv: `uv pip install --system` cannot create directory

  • A minimal code snippet that reproduces the bug.
uv pip install --python 3.12 pre-commit
Resolved 10 packages in 44ms
error: Failed to install: cfgv-3.4.0-py2.py3-none-any.whl (cfgv==3.4.0)
  Caused by: failed to create directory `/usr/local/lib/python3.12/dist-packages/cfgv-3.4.0.dist-info`
  Caused by: Permission denied (os error 13)
  • The current uv platform.
Ubuntu 22.04
  • The current uv version (uv --version).
uv 0.1.12

pip defaults to .local/lib/python3.12/site-packages/ if the directory is not writeable

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 28 (18 by maintainers)

Most upvoted comments

This was also requested here: https://github.com/astral-sh/uv/issues/1584. I’m more open to supporting --user than to doing this automatic fallback.

(Aside: we plan to add pipx-like global installs for tools (https://github.com/astral-sh/uv/issues/1173). We actually have all the pieces we need to do this.)

In case you don’t want to implement this automatic fallback, I think a more specific error message would be helpful (e.g. pointing to --user or uv venv).

I think it’s totally fair not to include it. The only reason I mentioned it is that it sounded like you were planning to add it in a previous comment.

--prefix solution works fine too, at least with the official Docker images. Just needed to change PATH.

FROM ghcr.io/astral-sh/uv:0.2.24 as uv
FROM python:3.11.6
COPY --from=uv /uv /bin/uv

# Copy requirements file
WORKDIR /code
ARG REQFILE=requirements.txt
COPY $REQFILE .

# Do NOT use root
ARG USERNAME=appuser
RUN useradd -m $USERNAME
USER $USERNAME

# Install python dependencies
ENV PATH="/home/$USERNAME/.local/bin:$PATH"
ENV UV_HTTP_TIMEOUT=100 \
    UV_NO_CACHE=1 \
    UV_SYSTEM_PYTHON=1
RUN uv pip install -r $REQFILE --prefix "/home/$USERNAME/.local/"

Please see the extensive discussion at https://github.com/astral-sh/uv/issues/2077 regarding the --user flag and workarounds.

I don’t currently plan to support --user as I’m not yet convinced that it outweighs its complexity budget. In other words, it adds a lot of complexity (both to uv and to the user experience) but doesn’t strike me as sufficiently useful to merit it – the situations in which folks want it seem rare and I feel like the alternative solutions are totally fine (I don’t think adding a venv is a big problem, nor is running with root privileges in a container). But I may change my mind on this in the future based on demand.

Yeah, that’s something we want to transparently support in the future.

Definitely!