Using uv as shebang line and adding requirements
Using uv as your shebang line – Rob Allen (HN comments) and more detailed article on this: Lazy self-installing Python scripts with uv
But especially Defining Python dependencies at the top of the file – Rob Allen and the PEP 723 – Inline script metadata | peps.python.org
You can add uv
to the shebang line as
#!/usr/bin/env -S uv run --script
And you can set requirements by adding this under the shebang line:
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "flickrapi",
# ]
# ///
Then you can uv run sync-flickr-dates.py
Full package:
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "flickrapi",
# ]
# ///
import flickrapi
print("\nI am running")
❯ chmod +x test.py
❯ ./test.py
Installed 11 packages in 134ms
I am running!
Neat!
Nel mezzo del deserto posso dire tutto quello che voglio.
comments powered by Disqus