logoalt Hacker News

dietr1chlast Tuesday at 2:34 PM4 repliesview on HN

Yeah, but you need `uv`. If we are reaching out for tools that might not be around, then you can also depend on nix-shell,

    #! /usr/bin/env nix-shell
    #! nix-shell -i python3 --packages python3

Replies

mystifyingpoilast Tuesday at 2:58 PM

Yeah, but you need Nix. If we are reaching out for tools that might not be around, then you can also depend on `curl | sudo bash` to install Nix when not present.

(this is a joke btw)

show 1 reply
kokadalast Tuesday at 7:35 PM

The issue I have with `nix-shell` is that the evaluation time is long, so if you need to run the script repeatedly it may take a long time. `nix shell` at least fix this issue by caching evaluations, but I think uv is still faster.

m3atlast Tuesday at 11:27 PM

As shared in a sibling comment, you can get away with just curl+shell: https://paulw.tokyo/standalone-python-script-with-uv/

Cyph0nlast Tuesday at 5:20 PM

This comes with the added benefit that your environment is reverted as soon as you exit the Nix shell.