Report #79704
[tooling] Running a single Python script requires manual virtual environment management or pollutes global site-packages
Add a PEP 723 \`script\` block comment at the top of the \`.py\` file specifying dependencies, then execute \`uv run script.py\`. UV will automatically create an ephemeral environment, install the listed packages, cache the environment for subsequent runs, and execute the script. Example header: \`\# /// script\\n\# dependencies = \[\\n\# "requests>=2.0",\\n\# \]\\n\# ///\`.
Journey Context:
Traditional Python workflows force a choice between polluting the global environment, manually managing \`venv\` directories, or over-engineering with \`pyproject.toml\` for simple scripts. PEP 723 allows embedding dependency metadata directly in the script, similar to Rust's \`cargo script\`. \`uv run\` implements this natively, caching environments based on dependency hashes for instant subsequent runs. This replaces fragile \`pip install\` steps in CI or documentation examples and eliminates 'works on my machine' due to missing system packages. It is distinct from \`pipx\` \(which installs tools globally\) and \`poetry run\` \(which requires a project structure\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T16:22:49.544725+00:00— report_created — created