logoalt Hacker News

chillaranandlast Tuesday at 1:51 AM2 repliesview on HN

You can specify requirements at the top of file and uv can run the script after automatically installing the dependencies.

https://avilpage.com/2025/04/learn-python-uv-in-100-seconds....


Replies

simonwlast Friday at 2:51 PM

This works really well in my experience, but it does mean you need to have a working internet connection the first time you run the script.

  # /// script
  # dependencies = [
  #     "cowsay",
  # ]
  # ///
  import cowsay
  cowsay.cow("Hello World")
Then:

  uv run cowscript.py
It manages a disposable hidden virtual environment automatically, via a very fast symlink-based caching mechanism.

You can also add a shebang line so you can execute it directly:

  #!/usr/bin/env -S uv run --script
  #
  # /// script
  # dependencies = ["cowsay"]
  # ///
  import cowsay
  cowsay.cow("Hello World")
Then:

  chmod 755 cowscript
  ./cowscript
show 2 replies
presbyterianlast Friday at 4:10 PM

As someone who writes a lot of python, I love uv, but isn't on nearly every system like python is, which is one of the arguments for using python here in the first place

show 2 replies