News for hackers. Stuff that matters.
Re:Go Away Python by meander_water on Tuesday December 30, 2025 @06:37AM (#46432267)
Actually you can go one better:

  #!/usr/bin/env -S uv run --python 3.14 --script
Then you don't even need python installed. uv will install the version of python you specified and run the command.
Re:Go Away Python by rikafurude21 on Tuesday December 30, 2025 @07:19AM (#46432575)
alternatively, uv lets you do this:

  #!/usr/bin/env -S uv run --script
  #
  # /// script
  # requires-python = ">=3.12"
  # dependencies = ["foo"]
  # ///
Re:Go Away Python by semi-extrinsic on Tuesday December 30, 2025 @09:47AM (#46433806)
The /// script block is actually specified in PEP 723 and supported by several other tools apart from uv.
Re:Go Away Python by yjftsjthsd-h on Tuesday December 30, 2025 @01:26PM (#46436298)
That's good to hear; do you know what other tools support it?
Re:Go Away Python by semi-extrinsic on Tuesday December 30, 2025 @01:53PM (#46436599)
From what I can tell, Hatch, PDM, pipx and pip-run also support it.
Re:Go Away Python by nemosaltat on Tuesday December 30, 2025 @02:32PM (#46436997)
The last time I commented extolling the virtues of uv on here, I got a similar reply, pointing out that PEP 723 specs this behavior, and uv isn’t the only way. So I’ll try again in this thread: I’m bullish on uv, and waiting for Cunningham.
Re:Go Away Python by semi-extrinsic on Tuesday December 30, 2025 @04:34PM (#46438292)
I am all in on uv as well, and advocating for its use heavily at $dayjob. But I think having as much as possible of these things encoded in standards is good for the ecosystem. Maybe in a few years time, someone will make something even better than uv. And in the meantime, having things standardised speeds up adoption in e.g. syntax highlighting in editors and such.
Re:Go Away Python by zahlman on Tuesday December 30, 2025 @10:02AM (#46433958)
This isn't really "alternatively"; it's pointing out that in addition to the shebang you can add a PEP 723 dependency specification that `uv run` (like pipx, and some other tools) can take into account.
Re:Go Away Python by ncouture on Tuesday December 30, 2025 @12:16PM (#46435498)
This is an awesome features for quick development.

I'm sure the documentation of this featureset highlights what I'm about to say but if you're attracted to the simplicity of writing Python projects who are initialized using this method, do not use this code in staging/prod.

If you don't see why this is not production friendly it's for the simple a good.reaaon that creating deployable artifacts packaging a project or a dependency of a project this uses this method, creating reproducible builds becomes impossible.

This will also lead to builds that pass your CI but fail to run in their destination environment and vice versa due to the fact that they download heir dependencies on the fly.

There may be workarounds and I know nothing of this feature so investigate yourself if you must.

My two cents.

Re:Go Away Python by nemosaltat on Tuesday December 30, 2025 @02:23PM (#46436905)
I’ve started migrating all of my ~15 years of one-off python scripts to have this front matter. Right now, I just update when/if I use them. I keep thinking if were handier with grep/sed/regex etc, I’d try to programmatically update .pys system-wide. But, many aren’t git tracked/version controlled, just laying in whatever dir they service(d). I’ve several times started a “python script dashboard” or “hacky tools coordinator” but stop when I remember most of these are unrelated (to each-other) and un/rarely used. I keep watching the chatter and thinking this is probably an easy task for codex, or some other agent but these pys are “mine” (and I knew^ how they worked when I wrote^ them) and also, they’re scattered and there’s no way I’m turning an agent loose on my file system.

^mostly, some defs might have StackOverflow copy/pasta

Re:Go Away Python by giancarlostoro on Tuesday December 30, 2025 @03:16PM (#46437481)
You could run ripgrep on your file system root to find most of them, its insanely fast, then feed it to claude or something to generate a script to do it for you.
Re:Go Away Python by rjzzleep on Wednesday December 31, 2025 @12:02AM (#46441457)
I'm actually a bit annoyed that uv won. I found pdm to be a really nice solution that fixed a lot of the issues poetry had without the hard ideological stance behind it, while fixing most of its problems. But maybe that ideology was partly what drove it's adoption.
Re:Go Away Python by satvikpendem on Wednesday December 31, 2025 @06:23PM (#46449399)
Rust is getting this feature too, it's great for one off scripts
Re:Go Away Python by dietr1ch on Tuesday December 30, 2025 @09:34AM (#46433683)
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
Re:Go Away Python by Cyph0n on Tuesday December 30, 2025 @12:20PM (#46435553)
This comes with the added benefit that your environment is reverted as soon as you exit the Nix shell.
Re:Go Away Python by fastasucan on Thursday January 01, 2026 @08:44AM (#46454057)
I dont think your emvironment is permanently changed with uv run?
Re:Go Away Python by Cyph0n on Thursday January 01, 2026 @01:59PM (#46456921)
Where does uv download the Python interpreter to?
Re:Go Away Python by exographicskip on Wednesday January 07, 2026 @05:41PM (#46534225)
By default, it's `~/Library/Caches/uv/environments-v2/` on macos.

Can find via `uv cache dir`

See: https://docs.astral.sh/uv/reference/cli/#uv-cache-dir

Re:Go Away Python by mystifyingpoi on Tuesday December 30, 2025 @09:58AM (#46433921)
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)

Re:Go Away Python by jonhohle on Tuesday December 30, 2025 @10:23AM (#46434182)
Yeah, but you need curl, sudo, and bash…
Re:Go Away Python by lioeters on Tuesday December 30, 2025 @12:47PM (#46435894)
"Give me a 190-byte hex0 seed of x86 assembly, and I shall compile the rest of the world." - Archimedes
Re:Go Away Python by Imustaskforhelp on Thursday January 01, 2026 @01:33PM (#46456674)
amazing quote. Adding it to my about page, do you want credit or shall I credit it to archimedes xD

On a serious note, its so brilliant that something like this is now possible when we think about it. It's maddeningly crazy to think about all the process but in the end that you can end up with a system / linux iso whose hash you can trust/independently verify and then you use it and spread around the world. Definitely makes me feel as sky's the only limit or just its very pleasant to think about it.

Re:Go Away Python by JodieBenitez on Tuesday December 30, 2025 @03:34PM (#46437669)
... you must first invent the universe
Re:Go Away Python by kokada on Tuesday December 30, 2025 @02:35PM (#46437037)
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.
Re:Go Away Python by m3at on Tuesday December 30, 2025 @06:27PM (#46439438)
As shared in a sibling comment, you can get away with just curl+shell: https://paulw.tokyo/standalone-python-script-with-uv/
Re:Go Away Python by jonhohle on Tuesday December 30, 2025 @10:22AM (#46434172)
That shebang will work on GNU link based systems, but might not work elsewhere. I know that’s the most popular target, but not working on macOS, BSDs, or even busybox.
Re:Go Away Python by rented_mule on Tuesday December 30, 2025 @11:45AM (#46435107)
I just tried the one you are replying to and it worked great on macOS. I frequently use a variant of this on my Mac.
Re:Go Away Python by jonhohle on Tuesday December 30, 2025 @07:30PM (#46439956)
That’s interesting. I wonder when that changed. Maybe FreeBSD supports multi arg shebangs now, too
Re:Go Away Python by shakna on Tuesday December 30, 2025 @09:34PM (#46440698)
The -S argument to env splits the argument on whitespace.

The shell doesn't support anything, it just passes the string to env.

So beware quoting and other delimiters that won't work the way you expect.

Re:Go Away Python by Supermancho on Tuesday December 30, 2025 @11:27AM (#46434912)
> Then you don't even need python installed. uv will install the version of python you specified and run the command

What you meant was, "you don't need python pre-installed". This does not solve the problem of not wanting to have (or limited from having) python installed.

Re:Go Away Python by m3at on Tuesday December 30, 2025 @06:25PM (#46439407)
And with some small shebang trick, you don't even need to have uv installed [1], just curl and a posix shell

[1] https://paulw.tokyo/standalone-python-script-with-uv/