Comment by mrweasel

13 days ago

While neat, doesn't it also comes with certain issues?

Startup times has to be slower, but probably only for the first run?

There's a some level of violation of the "Principle Of Least Surprise", depending on the setting. For some it will be the reverse, the script they got just works, without any setup or package installation. For others we'll wonder why it just started downloading a bunch of packages we already have.

Probably not the greatest idea for production environments, where you should not or can not just pull in packages from the internet.

It's really cool that it works, but I think I'd recommended using it highly selectively.

Definitely not for prod, but I used to have (and recommend: https://www.bitecode.dev/i/114175324/whats-a-good-name-for-a...) a giant venv just for my laptop scripts. Having one per script is too much, but none is inviting pain.

The problem with that is that eventually too many scripts means you will hit incompatibilities in Python where you can only install one version of a lib in each venv.

This trick is perfect because:

- From now on, I always install uv on all my machines anyway.

- After the first run, not only the cache make it fast, but it uses hard links so that you don't even pay the of multiple install on disk space (that's also how they are so fast in creating the envs, that and some interesting HTTP/zip tricks: https://www.bitecode.dev/p/charlie-marsh-on-astral-uv-and-th...).

- Deps are clearly defined in the script, so it's self-documenting.

For prod, shiv (https://shiv.readthedocs.io/) is probably your best bet but I'm betting uv will come up with a version of that soon.

  • I want to understand shiv, but I just can't grok it. I've successfully made a PyInstaller executable in the past.

    Do you have any good sources for learning shiv? The docs are very sparse & lack examples and there aren't as many blogs discussing shiv as I'd hoped.

    Also, do you know if shiv works on Windows?

    • Unfortunatly no, plus the docs are indeed not great and the UI itself is lacking.

      But yes, unlike pex, shiv works on windows.

      It's very different than pyinstaller in the sense that:

      - it uses a standard (the zipapp format from python stdlib)

      - it assumes python is already installed (it's not stand alone)

      I definitely should write on article on that on Bite Code on day. Adding it to the list.

      1 reply →

> but probably only for the first run?

It's slow on every run because it has to build the python virtual environment every time, even if it's cached all the packages

  • If you benchmark that you'll find uv spends microseconds getting the virtual environment up and running - that's its USP, they've invested a huge amount of work and ingenuity into making virtual environments so fast to create that you no longer have to think about that.

    (Mainly through tricks involving hard links)

> Probably not the greatest idea for production environments

Nor for any system where one takes care to not needlessly increase the threat surface.