logoalt Hacker News

lucideerlast Tuesday at 10:30 PM0 repliesview on HN

> How does uv solve the “write once, run anywhere” problem like go?

Here's an examply Python script from the uv website[0]:

  #!/usr/bin/env -S uv run --script
  #
  # /// script
  # requires-python = ">=3.12"
  # dependencies = ["httpx"]
  # ///

  import httpx

  print(httpx.get("https://example.com"))

This will auto-install Python 3.12 (or greater) in a per-script virtual environment, along with the httpx package from pypi & immediately execute the script, on any system that has uv.

[0] https://docs.astral.sh/uv/guides/scripts/#using-a-shebang-to...