Skip to content

.python-version overrides inline script metadata required-python for uv run #6883

@dbohdan

Description

@dbohdan

I ran a script with uv run, and .python-version in the current directory overrode required-python in the inline script metadata. The version in .python-version wasn't in the range of required-python. When the script ran with the wrong Python version, it failed. The problem took me five minutes to debug. I am not sure what should happen in this situation, but it confused me, so I am reporting it. (I think I'd prefer uv to either report a conflict in the Python version requirements and not run the script or to ignore .python-version in favor of required-python.)

I encountered this conflict on Ubuntu 24.04 on x86-64. uv was installed with pipx. Here is a POSIX shell script to reproduce it.

#! /bin/sh
set -e

uv --version

cat >demo.py <<EOF
#! /usr/bin/env -S uv run
# /// script
# dependencies = [
#   "httpx<2",
# ]
# requires-python = ">=3.10"
# ///

import sys
print(sys.version)
EOF

chmod +x demo.py

rm .python-version || true
./demo.py

echo 3.7 >.python-version
./demo.py

Output:

uv 0.4.1
Reading inline script metadata from: ./demo.py
Installed 7 packages in 4ms
3.12.1 (main, Jan 31 2024, 04:48:37) [GCC 11.4.0]
Reading inline script metadata from: ./demo.py
Installed 9 packages in 3ms
3.7.17 (default, Oct 16 2023, 22:17:29) 
[GCC 11.4.0]

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions