Live data from Hacker News

Self-contained Python scripts with uv

blog.dusktreader.dev

61–70 of 114 posts

Re: Self-contained Python scripts with uv

#61
post #51

This has come up a LOT on HN in the past few months, some other recent examples: https://news.ycombinator.com/item?id=43500124 https://news.ycombinator.com/item?id=42463975 I like uv and all, but I take exception to the "self-contained" claim in two regards: 1) The script requires uv to already be installed. Arguably you could make it a shell script that checks if uv is already installed and then installs it via curl…

Agree 100%. Using something like py2exe creates a self contained "python script". This comes with a lot of problems for the developer but minimum problems for the user.

Re: Self-contained Python scripts with uv

#62
post #51

This has come up a LOT on HN in the past few months, some other recent examples: https://news.ycombinator.com/item?id=43500124 https://news.ycombinator.com/item?id=42463975 I like uv and all, but I take exception to the "self-contained" claim in two regards: 1) The script requires uv to already be installed. Arguably you could make it a shell script that checks if uv is already installed and then installs it via curl…

Right, you need to have uv installed, and if you don't, you'll probably have to install it manually or through `curl | sh`. I think this is a valid complaint. Something to consider is that it will become less of an issue as package managers include uv in their repositories. For example, uv is already available in Alpine Linux and Homebrew: https://repology.org/project/uv/versions.

Another thing is that inline script metadata is a Python standard. When there is no uv on the system and uv isn't packaged but you have the right version of Python for the script, you can run the script with pipx: https://pipx.pypa.io/stable/examples/#pipx-run-examples. pipx is much more widely packaged: https://repology.org/project/pipx/versions.

Re: Self-contained Python scripts with uv

#63
post #21

My pet peeve (in general, not specific to UV, which I genuinely appreciate) is using comment sections for controlling code execution. Using comments for linters and developer notes is perfectly acceptable. However, for configuration or execution-related data, a far superior pattern would be something like: UV_ENV = { "dependencies": { "requests": "2.32.3", "pandas": "2.2.3" } } This approach has clear advantages: - I…

This isn't a uv invention, uv is only using the standard PEP 723 like other tools. https://peps.python.org/pep-0723/

As I mentioned, it is not criticism of uv, but of this general approach.

Re: Self-contained Python scripts with uv

#64

We do the same with Nix, the shebang line looks like this: #! nix-shell -i python3 -p "python312.withPackages (pkgs: [ pkgs.boto3 pkgs.click ])" With this, the only requirement is Nix on the system, you don't even need Python to be installed!

Having Nih installed is much stronger requirement than having uv

im not sure this is true

Re: Self-contained Python scripts with uv

#67
post #3

Has anyone gotten this to work on Windows? I wanted to use this trick for some tooling for a game mod I'm working on but couldn't get the shebang trick to work.

I'm not sure it's useful, but someone posted how to do a similar thing for Racket with PoweScript https://onor.io/2025/01/more-scripting-with-racket.html

Re: Self-contained Python scripts with uv

#68
I do not really understand how this is self contained, when you have to install additional software to run it.

my approach is to use python build-in venv https://gist.github.com/Szpadel/43794d606d9924e7fea3e63fb800...

that way you can run scripts with external packages with only basic python installation

Re: Self-contained Python scripts with uv

#69

Earlier quoted context omitted.

As I understand it, relicensing is possible when a project has a Contributor Licensing Agreement (CLA) which says that you're signing over your copyright to your contribution to the project's owners. (Who will eventually be bought out by the worst rich person you can think of - Yes, him.) I peeked in uv's contributing guide and issues and didn't see any CLA. In PyTorch the CLA was mentioned at the top of the contribu…

Not having a CLA prevents relicensing but open source licenses aren't revokable anyways.

That's not been tested much in the courts. Recent rulings suggest OSS at least has consideration and thus can't be blanket terminated without some justification, but the USC provides that justification (with some onerous requirements -- 2-10 years of notice, has to happen in a certain time window, ...), even for licenses stating irrevocability.

Re: Self-contained Python scripts with uv

#70

Earlier quoted context omitted.

I use this frequently on Windows and Linux. These are the steps I take: $> uv init --script .py $> uv add --script .py ... $> uv add --script .py --dev ... $> uv run .py Hope this helps :) Source: https://docs.astral.sh/uv/guides/scripts/

Unfortunately, `uv add --dev` doesn't work with `--script`: > uv -V uv 0.6.10 > uv add --script foo.py --dev ruff error: the argument '--script ' cannot be used with '--dev' Usage: uv add --script --link-mode > For more information, try '--help'. There is currently no mention of `uv add --script foo.py --dev ...` in https://docs.astral.sh/uv/guides/scripts/ . Inline script metadata in Python doesn't standardize devel…

Interesting about the --deb flag not working with scripts. I wrote this from memory and feel like I've installed dev dependencies for a script, but it must be a hallucination because I just tried and it doesn't work. Thanks for the correction.
Post reply on HN