Live data from Hacker News

Switching from Pyenv to Uv

bluesock.org

171–180 of 239 posts

Re: Switching from Pyenv to Uv

#171
post #154

I switched to hatch last year for many projects, its been quite pleasant. Has anyone used both hatch and uv, and could comment on that comparison? EDIT: quick google gives me these opinions[1] [1]: https://www.reddit.com/r/Python/comments/1gaz3tm/hatch_or_uv...

We had to drop hatch for now, because it does not work well with uv's lockfiles. Someone opened an issue here: https://github.com/pypa/hatch/issues/1886. We use bare uv for now.

Re: Switching from Pyenv to Uv

#172
post #36

Earlier quoted context omitted.

The install speed alone makes it worthwhile for me. It went from minutes to seconds.

I was working on a Raspberry Pi at a hackathon, and pip install was eating several minutes at a time. Tried uv for the first time and it was down to seconds.

Why would you be redoing your venv more than once?

Re: Switching from Pyenv to Uv

#173
post #9
post #2

has anybody doing complex projects achiever success with uv completely replacing pyenv, and had mostly pros and few or no cons? I'm very comfortable with pyenv, but am extremely open to new stuff

I worked in a large-ish org where 20+ python projects, their CI/CD pipelines and their docker images were migrated from `pyenv` + `.python-version` + `requirements.txt` to `uv` in basically a single day. If you are comfortable with `pyenv`, the switch to `uv` is basically a walk in the park. The benefit is the speed + the predictable dependencies resolution.

Astral ships a Docker image that provides their tox-uv. I saw maybe a 3x speed up setting up environments.

Re: Switching from Pyenv to Uv

#174

For scripting... HIGHLY recommend putting your dependencies inline. E.g.: #!/usr/bin/env python3 # /// script # requires-python = ">=3.11" # dependencies = [ # "psycopg2-binary", # "pyyaml", # ] # /// Then - uv run -s file.py

Do you need a wrapper script for scripts in the PATH or execve? I would usualy chmod+x the script but I am not sure here.

Discussed here:

> Using uv as your shebang line

https://news.ycombinator.com/item?id=42855258

Since `env` doesn’t pass multiple arguments by default, the suggested line uses `-S`:

   #!/usr/bin/env -S uv run --script

Re: Switching from Pyenv to Uv

#175
post #137
post #40

Earlier quoted context omitted.

Agree. I mostly do front end in my day job, and despite JavaScript being a bit of a mess lang, dealing with npm is way better than juggling anaconda, miniforge, Poetry, pip, venv, etc depending on the project. UV is such a smooth UX that it makes you wonder how something like it wasn’t part of Python from the start.

More importantly, migrating from npm, to pnpm, to yarn, to bun, is very nearly seamless. Migrating in the Python ecosystem? Not anywhere close.

standardizing pyproject.toml helped but it didn't go quite far enough.

Re: Switching from Pyenv to Uv

#176
post #114

Earlier quoted context omitted.

I generally agree but one thing I find very frustrating (i.e. have not figured out yet) is how deal with extras well, particularly with pytorch. Some of my machines have GPU, some don't and things like "uv add" end up uninstalling everything and installing the opposite forcing a resync with the appropriate --extra tag. The examples in the docs do things like CPU on windows and GPU on Linux but all my boxes are linux.…

Getting the right version of PyTorch installed to have the correct kind of acceleration on each different platform you support has been a long-standing headache across many Python dependency management tools, not just uv. For example, here's the bug in poetry regarding this issue: https://github.com/python-poetry/poetry/issues/6409 As I understand it, recent versions of PyTorch have made this process somewhat easier,…

On nvidia jetson systems, I always end up compiling torchvision, while torch always comes as a wheel. It seems so random.

Re: Switching from Pyenv to Uv

#178

Earlier quoted context omitted.

Usually the VENV and import lines are enough

How do you determine where the venv is? AFAIK, uv run in script mode creates the venv in some random temporary directory.

I don’t know of a convenient way of doing it, but a clumsy way of doing it is to run this in your script:

  import os
  
  print(os.environ['VIRTUAL_ENV'] + '/bin/python')
Then, e.g. in VS Code, you bring up the command palette, run Python: Select Interpreter, and enter the result.

Re: Switching from Pyenv to Uv

#180
post #40

Earlier quoted context omitted.

Agree. I mostly do front end in my day job, and despite JavaScript being a bit of a mess lang, dealing with npm is way better than juggling anaconda, miniforge, Poetry, pip, venv, etc depending on the project. UV is such a smooth UX that it makes you wonder how something like it wasn’t part of Python from the start.

Feels like you're doing it wrong if you're dealing with all of those.

"depending on the project"
Post reply on HN