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

uv venv --python <version> fails when querying managed python interpreter on alpine #6392

Closed
SamuelMarks opened this issue Aug 21, 2024 · 13 comments
Labels
bug Something isn't working musl

Comments

@SamuelMarks
Copy link

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?

@charliermarsh
Copy link
Member

Yeah, you should be able to use UV_PYTHON_INSTALL_DIR.

@charliermarsh
Copy link
Member

Is PYTHON_VERSION just set to 3.11 here?

@SamuelMarks
Copy link
Author

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?

@charliermarsh
Copy link
Member

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).

@charliermarsh
Copy link
Member

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

@SamuelMarks
Copy link
Author

SamuelMarks commented Aug 21, 2024

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)
------

@zanieb
Copy link
Member

zanieb commented Aug 22, 2024

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

@zanieb
Copy link
Member

zanieb commented Aug 22, 2024

More context on why we aren't downloading musl distributions (as we should) in #4160

Progress towards that can be tracked in #4242

@zanieb
Copy link
Member

zanieb commented Aug 22, 2024

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)

@zanieb zanieb changed the title [0.3.0] uv venv --python <version> fails to download python uv venv --python <version> fails when querying managed python interpreter on alpine Aug 22, 2024
@konstin
Copy link
Member

konstin commented Aug 22, 2024

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)

@konstin konstin added bug Something isn't working musl labels Aug 26, 2024
@konstin konstin removed their assignment Sep 2, 2024
@konstin
Copy link
Member

konstin commented Sep 2, 2024

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.

@zanieb
Copy link
Member

zanieb commented Sep 3, 2024

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.

@zanieb zanieb closed this as completed Sep 3, 2024
@SamuelMarks
Copy link
Author

Separately there's always αpε to consider… e.g., with superconfigure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working musl
Projects
None yet
Development

No branches or pull requests

4 participants