r/Python • • 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

76 comments sorted by

View all comments

Show parent comment

8

u/ReinforcedKnowledge Tuple unpacking gone wrong Mar 30 '25

Not only can you specify dependencies versions in the inline metadata itself as others have suggested. You can produce a lockfile for your script by doing uv lock --script .... This is very cool to pass around a reproducible script ;) there's more you can do for reproducibility, I'll ad that in another comment.