`uv venv --python <version>` fails when querying managed python interpreter on alpine
Saw your release notes and thought - perfect:
uv venv --python
will automatically download the Python version if required
So gave it a shot:
FROM alpine
ARG RYE_VER="0.39.0"
ARG UV_VER="0.3.0"
ARG VENV_DIR = "/tmp/foo/venvs"
ARG VENV_NAME = "venv-3-11"
WORKDIR /tmp
ADD "https://github.com/astral-sh/rye/releases/download/${RYE_VER}/rye-x86_64-linux.gz" .
ADD "https://github.com/astral-sh/uv/releases/download/${UV_VER}/uv-x86_64-unknown-linux-musl.tar.gz" .
RUN gzip -vd rye-x86_64-linux.gz && chmod +x rye-x86_64-linux && \
mv rye-x86_64-linux /usr/local/bin/rye && \
tar xfv uv-x86_64-unknown-linux-musl.tar.gz && \
chmod +x uv-x86_64-unknown-linux-musl/* && \
mv uv-x86_64-unknown-linux-musl/* /usr/local/bin/
RUN uv venv --python "${PYTHON_VERSION}" "${VENV_DIR}/${VENV_NAME}"
ENTRYPOINT ["${VENV_DIR}/${VENV_NAME}/bin/python", "--version"]
Error:
commit: 0.39.0 (bf3ccf818 2024-08-21)
platform: linux (x86_64)
self-python: not bootstrapped (target: [email protected])
symlink support: true
uv enabled: true
× Failed to query Python interpreter at
│ `/root/.local/share/uv/python/cpython-3.11.9-linux-x86_64-gnu/bin/python3`
╰─▶ No such file or directory (os error 2)
PS: Would be nice to keep things out of /root, is there a flag to set that directory?
Yeah, you should be able to use UV_PYTHON_INSTALL_DIR.
Is PYTHON_VERSION just set to 3.11 here?
Sorry yes that is just 3.11. It brings in the latest patch from my reading of the docs? - Or do I need to specify patch version also?
No 3.11 is totally fine, it just wasn't in the script so confirming.
I think we don't yet have proper musl detection (\cc @konstin who knows this best). That script does work for me with dynamically-linked glibc (e.g. FROM ubuntu or similar).
I'm very confused by No such file or directory, I get a different error on my machine but I'm emulating on macOS:
#12 1.436 × Querying Python at
#12 1.436 │ `/root/.local/share/uv/python/cpython-3.11.9-linux-x86_64-gnu/bin/python3`
#12 1.436 │ failed with exit status signal: 5 (SIGTRAP)
#12 1.436 │ --- stdout:
#12 1.436
#12 1.436 │ --- stderr:
#12 1.436 │ rosetta error: failed to open elf at /lib64/ld-linux-x86-64.so.2
Oh right looks like you'll need musl-dev, here's the full replication:
FROM alpine
ARG RYE_VER="0.39.0"
ARG UV_VER="0.3.0"
ARG VENV_DIR="/tmp/foo/venvs"
ARG VENV_NAME="venv-3-11"
ARG PYTHON_VERSION="3.11"
ENV UV_PYTHON_INSTALL_DIR="/tmp/uv"
RUN apk add --no-cache musl-dev
WORKDIR /tmp
ADD "https://github.com/astral-sh/rye/releases/download/${RYE_VER}/rye-x86_64-linux.gz" .
ADD "https://github.com/astral-sh/uv/releases/download/${UV_VER}/uv-x86_64-unknown-linux-musl.tar.gz" .
RUN gzip -vd rye-x86_64-linux.gz && chmod +x rye-x86_64-linux && \
mv rye-x86_64-linux /usr/local/bin/rye && \
tar xfv uv-x86_64-unknown-linux-musl.tar.gz && \
chmod +x uv-x86_64-unknown-linux-musl/* && \
mv uv-x86_64-unknown-linux-musl/* /usr/local/bin/
RUN uv venv --python "${PYTHON_VERSION}" "${VENV_DIR}/${VENV_NAME}"
ENTRYPOINT ["${VENV_DIR}/${VENV_NAME}/bin/python", "--version"]
Gives:
> [7/7] RUN uv venv --python "3.11" "/tmp/foo/venvs/venv-3-11":
21.69 × Failed to query Python interpreter at
21.69 │ `/tmp/uv/cpython-3.11.9-linux-x86_64-gnu/bin/python3`
21.69 ╰─▶ No such file or directory (os error 2)
------
I've reproduced this — I think it's complaining that GNU Libc is not found (in a very cryptic way)
https://stackoverflow.com/questions/77418700/python-not-found-in-alpine-image
More context on why we aren't downloading musl distributions (as we should) in https://github.com/astral-sh/uv/pull/4160
Progress towards that can be tracked in https://github.com/astral-sh/uv/issues/4242
Interestingly if you force a musl download, e.g., with:
RUN uv venv -v --python "cpython-${PYTHON_VERSION}-linux-x86_64-musl" "${VENV_DIR}/${VENV_NAME}"
We still fail
2.624 × Can't use Python at
2.624 │ `/root/.local/share/uv/python/cpython-3.11.9-linux-x86_64-musl/bin/python3`
2.624 ╰─▶ Could not detect a glibc or a musl libc (while running on Linux)
cpython-3.11.9-linux-x86_64-musl/bin/python3 is statically linked, so we fail to determine an interpreter (such as /lib64/ld-linux-x86-64.so.2)
Since we don't have a properly working Python interpreter for musl, we now show a correct error message that you need to install Python using the system tools (e.g. apk add python3). We plan to serve Python downloads for musl in the future; For now you should be getting a correct error message.
We no longer provide managed interpreters due to this error. We can track this in #6890 now — but this is an upstream python-build-standalone issue.
Separately there's always αpε to consider… e.g., with superconfigure