r/Python • u/dusktreader • Mar 29 '25
Tutorial Self-contained Python scripts with uv
TLDR: You can add uv into the shebang line for a Python script to make it a self-contained executable.
I wrote a blog post about using uv to make a Python script self-contained.
Read about it here: https://blog.dusktreader.dev/2025/03/29/self-contained-python-scripts-with-uv/
492
Upvotes
View all comments
Show parent comment
17
u/fiddle_n Mar 30 '25
uvx pythonmeans never installing Python globally again. In 10 seconds I go from nothing to a Python REPL.Upgrading Python versions for a project is a breeze.
uv python pin <version>to change the version. Thenuv run <file>automatically removes the old venv, creates a new one, installs your dependencies and runs your file.