Live data from Hacker News

Self-contained Python scripts with uv

blog.dusktreader.dev

91–100 of 114 posts

Re: Self-contained Python scripts with uv

#91
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…

You usually have to install something before you can run a program on your computer, so installing uv doesn't seem that bad to me. I still wouldn't call this self-contained because when you run the program it downloads who knows what from the internet!

To me, fully self-contained is something more like an AppImage

Re: Self-contained Python scripts with uv

#92
Overall, and admittedly from a bit of a distance, uv run feels like a reinvention of Zero Install, but for only Python.

I also wondered why virtual environments were invented for Python when general environment managers (like Modules) already existed.

These packaging and environment problems have never been specific to Python

https://0install.net/ https://modules.sourceforge.net/

Re: Self-contained Python scripts with uv

#93
post #48

Earlier quoted context omitted.

Different python versions have different syntax grammars, so if the rest of your file has new syntax, and older python might not be able to execute even the first few lines. For example if you run this on python3.6: print("hello") match 123: case _: pass you won't even get a "hello".

What is the problem with that? I see no reason to expect that would work.

The whole point of writing a "self-contained" script is that it should run anywhere. uv bundles its own cpython runtime(s) for this purpose, but relying on script execution prior to invocation of uv breaks this.

The trick in the featured article would allow me to drop a script written in modern python syntax on my outdated ubuntu LTS box and have it "just work", while GP's suggestion would not.

Re: Self-contained Python scripts with uv

#94
post #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

Your version needs Python. uv needs needs only uv, as it can manage python installation by itself. It's also a lot easier to install uv than to manage Python installations (there's a reason pyenv and the like exist).

That's fair point. Its maybe different use case. For me main goal was to be able to run project scripts on macos and Linux ootb, and both have some python 3 version already available ootb.

But probably if you need specific python version it isn't best way

Re: Self-contained Python scripts with uv

#95
post #94

Earlier quoted context omitted.

Your version needs Python. uv needs needs only uv, as it can manage python installation by itself. It's also a lot easier to install uv than to manage Python installations (there's a reason pyenv and the like exist).

That's fair point. Its maybe different use case. For me main goal was to be able to run project scripts on macos and Linux ootb, and both have some python 3 version already available ootb. But probably if you need specific python version it isn't best way

[dead]

Re: Self-contained Python scripts with uv

#96
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…

[dead]

Re: Self-contained Python scripts with uv

#98
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…

curl | sh is an abhorrent practice and should never be used.

Re: Self-contained Python scripts with uv

#99
post #87

Earlier quoted context omitted.

The regular CPython installer on Windows installs the py launcher and associates it with .py files. The py launcher supports shebang lines. This was covered in a blog post about this same topic that was posted here a few days ago. According to that you have to omit the -S: https://thisdavej.com/share-python-scripts-like-a-pro-uv-and... https://news.ycombinator.com/item?id=43500124 I haven't tried it myself, I simply…

Interesting. The workflow I've been using skips the CPython installer and only uses uv.

Windows doesn't support shebang lines as you probably know, but if you associate uv with .py files you'll get the same result.

I think it should be something like this:

  ftype Python.File=C:\Path\to\uv.exe run %L %*
If you don't use the CPython installer the Python.File file type might not be defined, so you might need to set that with `assoc` first:

  assoc .py=Python.File

Re: Self-contained Python scripts with uv

#100
post #92

Overall, and admittedly from a bit of a distance, uv run feels like a reinvention of Zero Install, but for only Python. I also wondered why virtual environments were invented for Python when general environment managers (like Modules) already existed. These packaging and environment problems have never been specific to Python https://0install.net/ https://modules.sourceforge.net/

uv has little in common with 0install, which has its origins in RISC OS's application directories.

uv is an attempt to fix the fragments Python development environment tooling story.

Post reply on HN