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

requires-python = "~=3.10" uses docker container python 3.11 and not a managed python 3.10 #7682

Open
gabriel-vanzandycke opened this issue Sep 25, 2024 · 7 comments
Labels
needs-mre Needs more information for reproduction

Comments

@gabriel-vanzandycke
Copy link

gabriel-vanzandycke commented Sep 25, 2024

I use a docker container bundled with python 3.11.9 but my app requires python ~=3.10.
Running uv sync uses python system rather than the expected python version ~=3.10.
When enforcing ==3.10, uv downloads and uses a managed python version as expected.

Dockerfile

FROM python:3.11.9-slim-bookworm
COPY --from=ghcr.io/astral-sh/uv:0.4.10 /uv /bin/uv
ENTRYPOINT /bin/bash
ADD . /root

RUN --mount=type=cache,target=/root/.cache/uv \
    --mount=type=bind,source=uv.lock,target=uv.lock \
    --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
    uv sync --frozen --no-install-project --no-install-workspace > /tmp/uv_sync.log 2>&1

pyprojects.toml

[project]
name = "app"
version = "1.6.0"
description = ""
requires-python = "~=3.10"
dependencies = [
    "jupyter>=1.0",
]

[tool.uv]
package = true

With requires-python = "~=3.10" in pyproject.toml:
Inspecting the beginning of uv sync output shows it is using python 3.11.9.

$ docker build -t app:latest -f Dockerfile .
$ docker run -it --rm app:latest
# head -1 /tmp/uv_sync.log
Using Python 3.11.9 interpreter at: /usr/local/bin/python3

With requires-python = "==3.10" in pyproject.toml:
When requiring 3.10 instead, inspecting the uv sync output shows it is using python 3.10 as expected.

$ docker build -t app:latest -f Dockerfile .
$ docker run -it --rm app:latest
root@d93a4e3c8011:/# head -1 /tmp/uv_sync.log
Using Python 3.10.0
@gabriel-vanzandycke gabriel-vanzandycke changed the title requires-python = "~=3.10" uses docker container python 3.11 and not a python 3.10 requires-python = "~=3.10" uses docker container python 3.11 and not a managed python 3.10 Sep 25, 2024
@gabriel-vanzandycke gabriel-vanzandycke changed the title requires-python = "~=3.10" uses docker container python 3.11 and not a managed python 3.10 requires-python = "~=3.10" uses docker container python 3.11 and not a managed python 3.10 Sep 25, 2024
@weihenglim
Copy link

weihenglim commented Sep 25, 2024

The version specifier ~=3.10 is equivalent to >=3.10, ==3.*, which matches 3.11

You should specify ~=3.10.0 if you want to target Python 3.10.*

@gabriel-vanzandycke
Copy link
Author

Thanks. I didn't know that.

@gabriel-vanzandycke
Copy link
Author

I still have the problem with ~=3.10.0 though

@gabriel-vanzandycke
Copy link
Author

it's not easy to replicate my exact setup in a minimum working example, but when I use ~=3.10.0, running

uv run jupyter notebook

and importing one of my dependency within a notebook fails with "module not found". It all seems like uv run is not loading/using the environment created previously.

@weihenglim
Copy link

I'm not familiar with jupyter but you can try taking a look at #7679 (comment)

@charliermarsh
Copy link
Member

If ~=3.10.0 is giving you 3.11.X, that may be a bug.

@charliermarsh
Copy link
Member

I cannot produce that:

Using Python 3.11.7
error: The requested interpreter resolved to Python 3.11.7, which is incompatible with the project's Python requirement: `>=3.10.0, <3.11`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-mre Needs more information for reproduction
Projects
None yet
Development

No branches or pull requests

3 participants