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 sync fails when interpreter is not named python[3] #4709

Closed
zanieb opened this issue Jul 1, 2024 · 4 comments · Fixed by #5148
Closed

uv sync fails when interpreter is not named python[3] #4709

zanieb opened this issue Jul 1, 2024 · 4 comments · Fixed by #5148
Assignees
Labels
bug Something isn't working help wanted Contribution especially encouraged

Comments

@zanieb
Copy link
Member

zanieb commented Jul 1, 2024

See discussion in #4277

Instead of only searching for, e.g., python3.12 executables when Python 3.12 is requested (and not during the default search), we should use which_re (or a manually implemented which) to find all possible Python executables then filter them to meet the version request (if necessary).

@zanieb zanieb added enhancement New feature or improvement to existing functionality help wanted Contribution especially encouraged labels Jul 1, 2024
@zanieb
Copy link
Member Author

zanieb commented Jul 1, 2024

See python_executables_from_search_path for the current implementation.

@konstin konstin changed the title Search for all Python executable names uv sync fails when interpreter is not named python[3] Jul 10, 2024
@konstin konstin added bug Something isn't working and removed enhancement New feature or improvement to existing functionality labels Jul 10, 2024
@konstin
Copy link
Member

konstin commented Jul 10, 2024

The current behaviour is a problem when using pyenv: When using uv sync, uv fails to find a python interpreter even if it exists if the default python/python3 are incompatible.

For example with both requires-python = "==3.10.*" requires-python = ">=3.10", where the default python/python3 are any other version, say 3.9:

This fails:

uv sync --python-preference only-system

This passes:

uv sync --python-preference only-system -p 3.10

uv should find the python 3.10 interpreter in either case.

Reproduction

FROM ubuntu
ENV DEBIAN_FRONTEND=noninteractive
RUN apt update
RUN apt install -yy build-essential libssl-dev zlib1g-dev \
    libbz2-dev libreadline-dev libsqlite3-dev curl git \
    libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
RUN curl https://pyenv.run | bash
ENV PATH="/root/.pyenv/bin:$PATH"
RUN CONFIGURE_OPTS="--enable-optimizations" pyenv install 3.8.12 3.8.18
RUN CONFIGURE_OPTS="--enable-optimizations" pyenv install 3.9.18
RUN CONFIGURE_OPTS="--enable-optimizations" pyenv install 3.10.13
RUN CONFIGURE_OPTS="--enable-optimizations" pyenv install 3.11.7
RUN CONFIGURE_OPTS="--enable-optimizations" pyenv install 3.12.1
RUN pyenv global 3.8.12 3.8.18 3.9.18 3.10.13 3.11.7 3.12.1
# https://github.com/pyenv/pyenv#set-up-your-shell-environment-for-pyenv
RUN echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc \
    && echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc \
    && echo 'eval "$(pyenv init -)"' >> ~/.bashrc

Create a dummy pyproject.toml, any requires-python that mismatches the default active python will do:

[project]
name = "a"
version = "0.1.0"
requires-python = "==3.10.*"
dependencies = ["tqdm"]

Compile uv:

cargo build --release --target x86_64-unknown-linux-musl

Start the docker container, mount the uv dir to /io and run commands with

/io/target/x86_64-unknown-linux-musl/release/uv sync

@charliermarsh
Copy link
Member

I think this needs an owner. @konstin?

@konstin konstin self-assigned this Jul 17, 2024
@konstin
Copy link
Member

konstin commented Jul 17, 2024

Will do

konstin added a commit that referenced this issue Jul 17, 2024
Search for all `python3.x` minor versions, skipping those we already know we can use.

For example. let's say `python` and `python3` are Python 3.10. When a user requests `>= 3.11`, we still need to find a `python3.12` in PATH.

Fixes #4709
konstin added a commit that referenced this issue Jul 17, 2024
Search for all `python3.x` minor versions, skipping those we already know we can use.

For example. let's say `python` and `python3` are Python 3.10. When a user requests `>= 3.11`, we still need to find a `python3.12` in PATH.

Fixes #4709
konstin added a commit that referenced this issue Jul 18, 2024
Search for all `python3.x` minor versions in PATH, skipping those we
already know we can use.

For example, let's say `python` and `python3` are Python 3.10. When a
user requests `>= 3.11`, we still need to find a `python3.12` in PATH.
We do so with a regex matcher.

Fixes #4709
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Contribution especially encouraged
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants