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

Specify specific or maximum Python version #74

Closed
domoritz opened this issue Jan 27, 2025 · 3 comments
Closed

Specify specific or maximum Python version #74

domoritz opened this issue Jan 27, 2025 · 3 comments

Comments

@domoritz
Copy link

domoritz commented Jan 27, 2025

I got a bit confused that juv init --python=3.9 notebook.ipynb installs at least Python 3.9 rather than specifically 3.9. Maybe the command should be juv init --python='>=3.9' notebook.ipynb or juv init --min_python=3.9 notebook.ipynb.

I see that this option corresponds to the UV_PYTHON variable so maybe this "works as intended" but at least I wanted to drop a note here if someone else runs into this. I was able to specify a max version in the notebook itself.

# /// script
# requires-python = "<3.10"
# dependencies = [
# ]
# ///
@domoritz
Copy link
Author

I think I was holding this wrong. The python version isn't really specified in the notebook but instead in the run command.

juv run --python=3.9 notebook.ipynb. I'm not sure there is an issue here.

@manzt
Copy link
Owner

manzt commented Jan 27, 2025

I see that this option corresponds to the UV_PYTHON variable so maybe this "works as intended" but at least I wanted to drop a note here if someone else runs into this.

Indeed, the behavior is inherited from uv (e.g., uv init --python=3.9 --script foo.py), where the semantics set the lower bound of the requires-python field in the metadata.

I think this makes sense for pure Python scripts, as they should be forward-compatible between minors.... however, an issue often arises with binaries or wheels for dependencies, where a new Python release may lack a compatible wheel. In that case, I'd prefer the latest-compatible Python version with a wheel (rather than triggering a build).

I recommend providing the flag with run or manually pinning an upper bound in the inline metadata (as you have shown). More broadly, in my experience the relationship between requested Python and dependencies has a little friction (and potentially different semantics).

@manzt manzt pinned this issue Jan 27, 2025
@manzt
Copy link
Owner

manzt commented Jan 27, 2025

I'm going to pin this issue because I don't know the resolution (but I assume there might be some discussion in uv about this same thing for standalone scripts).

@manzt manzt closed this as completed Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants