TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Uv's killer feature is making ad-hoc environments easy

502 点作者 astronautas4 个月前

36 条评论

nharada4 个月前
I really like uv, and it's the first package manager for a while where I haven't felt like it's a minor improvement on what I'm using but ultimately something better will come out a year or two later. I'd love if we standardized on it as a community as the de facto default, especially for new folks coming in. I personally now recommend it to nearly everyone, instead of the "welllll I use poetry but pyenv works or you could use conda too"
评论 #42676849 未加载
评论 #42676863 未加载
评论 #42677745 未加载
评论 #42677639 未加载
评论 #42679112 未加载
评论 #42679317 未加载
riwsky4 个月前
Heck, you can get even cleaner than that by using uv’s support for PEP 723’s inline script dependencies:<p><pre><code> # &#x2F;&#x2F;&#x2F; script # requires-python = &quot;&gt;=3.12&quot; # dependencies = [ # &quot;pandas&quot;, # ] # &#x2F;&#x2F;&#x2F; </code></pre> h&#x2F;t <a href="https:&#x2F;&#x2F;simonwillison.net&#x2F;2024&#x2F;Dec&#x2F;19&#x2F;one-shot-python-tools&#x2F;" rel="nofollow">https:&#x2F;&#x2F;simonwillison.net&#x2F;2024&#x2F;Dec&#x2F;19&#x2F;one-shot-python-tools&#x2F;</a>
评论 #42704620 未加载
评论 #42677455 未加载
评论 #42679080 未加载
评论 #42677267 未加载
评论 #42679321 未加载
stevage4 个月前
As a NodeJS developer it&#x27;s still kind of shocking to me that Python still hasn&#x27;t resolved this mess. Node isn&#x27;t perfect, and dealing with different versions of Node is annoying, but at least there&#x27;s none of this &quot;worry about modifying global environment&quot; stuff.
评论 #42676978 未加载
评论 #42677075 未加载
评论 #42677348 未加载
评论 #42679623 未加载
评论 #42677319 未加载
评论 #42677139 未加载
评论 #42679409 未加载
评论 #42677036 未加载
评论 #42680893 未加载
评论 #42677110 未加载
评论 #42677329 未加载
评论 #42686440 未加载
评论 #42681966 未加载
bityard4 个月前
I usually stay away far FAR from shiny new tools but I&#x27;ve been experimenting with uv and I really like it. I&#x27;m a bit bummed that it&#x27;s not written in Python but other than that, it does what it says on the tin.<p>I never liked pyenv because I really don&#x27;t see the point&#x2F;benefit building every new version of Python you want to use. There&#x27;s a reason I don&#x27;t run Gentoo or Arch anymore. I&#x27;m very happy that uv grabs pre-compiled binaries and just uses those.<p>So far I have used it to replace poetry (which is great btw) in one of my projects. It was pretty straightforward, but the project was also fairly trivial&#x2F;typical.<p>I can&#x27;t fully replace pipx with it because &#x27;uv tool&#x27; currently assumes every Python package only has one executable. Lots of things I work with have multiple, such as Ansible and Jupyterlab. There&#x27;s a bug open about it and the workarounds are not terrible, but it&#x27;d be nice if they are able to fix that soon.
评论 #42680303 未加载
emiller884 个月前
There&#x27;s so many more!<p>1. `uvx --from git+<a href="https:&#x2F;&#x2F;github.com&#x2F;httpie&#x2F;cli">https:&#x2F;&#x2F;github.com&#x2F;httpie&#x2F;cli</a> httpie` 2. <a href="https:&#x2F;&#x2F;simonwillison.net&#x2F;2024&#x2F;Aug&#x2F;21&#x2F;usrbinenv-uv-run&#x2F;" rel="nofollow">https:&#x2F;&#x2F;simonwillison.net&#x2F;2024&#x2F;Aug&#x2F;21&#x2F;usrbinenv-uv-run&#x2F;</a> uv in a shebang
评论 #42677054 未加载
评论 #42676986 未加载
评论 #42677953 未加载
supakeen4 个月前
The activation of the virtualenv is unnecessary (one can execute pip&#x2F;python directly from it), and the configuring of your local pyenv interpreter is also unnecessary, it can create a virtual environment with one directly:<p><pre><code> pyenv virtualenv python3.12 .venv .venv&#x2F;bin&#x2F;python -m pip install pandas .venv&#x2F;bin&#x2F;python </code></pre> Not quite one command, but a bit more streamlined; I guess.
评论 #42677044 未加载
评论 #42676817 未加载
egeres4 个月前
This is super cool, personally:<p>uv run --python 3.12 --with label-studio label-studio<p>Made my life so much easier
lukax4 个月前
Uv also bundles uvx command so you can run Python scripts without installing them manually:<p>uvx --from &#x27;huggingface_hub[cli]&#x27; huggingface-cli
评论 #42677340 未加载
评论 #42676780 未加载
krick4 个月前
Ok, this must be a dumb question answered by the manual, but I still haven&#x27;t got my hands on uv, so: but does it solve the opposite? I mean, I pretty much never want any &quot;ad-hoc&quot; environments, but I always end up with my .venv becoming an ad-hoc environment, because I install stuff while experimenting, not bothering to patch requirements.txt, pyproject.toml or anything of the sort. In fact, now I usually don&#x27;t even bother typing pip install, PyCharm does it for me.<p>This is of course bad practice. What I would like instead is what PHP&#x27;s composer does: installing stuff automatically changes pyprpject.toml (or whatever the standard will be with uv), automatically freezes the versions, and then it is on git diff to tell me what I did last night, I&#x27;ll remove a couple of lines from that file, run composer install and it will remove packages not explicitly added to my config from the environment. Does this finally get easy to achieve with uv?
评论 #42680821 未加载
评论 #42680778 未加载
评论 #42680463 未加载
评论 #42680441 未加载
wruza4 个月前
Why can’t python just adopt something like yarn&#x2F;pnpm + and effing stop patch-copying its binaries into a specific path? And pick up site_packages from where it left it last time? Wtf. How hard it is to just pick python-modules directory and python-project.json and sync it into correctness by symlink&#x2F;mklink-inf missing folders from a package cache in there in a few seconds?<p>Every time when I have to reorganize or upgrade my AI repos, it’s yet another 50GB writes to my poor ssd. Half of it is torch, another half auto-downloaded models that I cannot stop because they become “downloaded” and you never know how to resume it back or even find where they are cause python logging culture is just barbaric.
tandav4 个月前
I&#x27;m waiting for this issue to be done: Add an option to store virtual environments in a centralized location outside projects <a href="https:&#x2F;&#x2F;github.com&#x2F;astral-sh&#x2F;uv&#x2F;issues&#x2F;1495">https:&#x2F;&#x2F;github.com&#x2F;astral-sh&#x2F;uv&#x2F;issues&#x2F;1495</a><p>I have used virtualenvwrapper before and it was very convenient to have all virtual environments stored in one place, like ~&#x2F;.cache&#x2F;virtualenvs.<p>The .venv in the project directory is annoying because when you copy folder somewhere you start copying gigabytes of junk. Some tools like rsync can&#x27;t handle CACHEDIR.TAG (but you can use --exclude .venv)
forgingahead4 个月前
Python package management has always seemed like crazyland to me. I&#x27;ve settled on Anaconda as I&#x27;ve experimented with all the ML packages over the years, so I&#x27;d be interested to learn why uv, and also what&#x2F;when are good times to use venv&#x2F;pip&#x2F;conda&#x2F;uv&#x2F;poetry&#x2F;whatever else has come up.<p>NeutralCrane has a really helpful comment below[0], would love to have a more thorough post on everything!<p>[0]<a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=42677048">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=42677048</a>
评论 #42682972 未加载
greatgib4 个月前
Ridiculous post:<p>The author says that a normal route would be:<p><pre><code> - Take the proper route: - Create a virtual environment - pip install pandas - Activate the virtual environment - Run python </code></pre> Basically, out of the box, when you create an virtual it is immediately activated. And you would obviously need to have it activated before doing a pip install...<p>In addition, in my opinion this is the thing that would sucks about UV to have different functions being tied to a single tool execution.<p>It is a breeze to be able to activate a venv, and be done with it, being able to run multiple times your program in one go, even with crashes, being able to install more dependencies, test it in REPL, ...
评论 #42681402 未加载
评论 #42678896 未加载
insane_dreamer4 个月前
been using conda for years with multiple projects each of which has numerous environments (for different versions). fairly large complex environments with coda, tf, jax, etc. has always worked well, and my biggest complaint - the sluggish resolver - largely addressed with mamba resolver. packages not available on conga-forge can be installed into the conda env pip. maybe I&#x27;m missing something but it&#x27;s not clear to me what advantage uv would provide over conda.
评论 #42680674 未加载
评论 #42706567 未加载
minimaxir4 个月前
What would be interesting is if you could do something similar for IPython&#x2F;Jupyter Notebooks: while front-ends like JupyterLab and VS Code Notebooks do let you select a .venv if present in the workspace, it&#x27;s annoying to have to set one up and build one for every project.
评论 #42678173 未加载
guru4consulting4 个月前
When using Maven build tool with Java, the downloaded artifacts always have the version number added to prefix (artifact-version.jar).. and that means there can be multiple versions stored in parallel, cached globally and cherry picked without any ambiguity. The first time when I used Node and Python, I was shocked that the version number is not part of any downloaded artifacts. Versioning the dependencies is such a fundamental need and having it part of the artifact file itself seems like a common sense to me. Can anyone please explain why the Python&#x2F;Node build tools do not follow that?
评论 #42721951 未加载
cyrialize4 个月前
For anyone that used rye, it&#x27;s worth noting that the creator of rye recommends using uv. Also, rye is going to be continually updated to just interface with uv until rye can be entirely replaced by uv.
评论 #42680942 未加载
CGamesPlay4 个月前
I want to like uv, but unfortunately there&#x27;s some kind of technical distinction between a Python &quot;package manager&quot; and a &quot;build system&quot;. Uv doesn&#x27;t include a &quot;build system&quot;, but encourages you to use some other one. The net result is that external dependencies don&#x27;t build the same as on Poetry, don&#x27;t work, and uv points the finger at some other dependency.<p>I do hope the situation changes one day. Python packaging is such a mess, but Poetry is good enough and actually works, so I&#x27;ll stick with it for now.
评论 #42681337 未加载
评论 #42685214 未加载
tasn4 个月前
OK, I&#x27;m convinced. I just installed uv. Thanks for sharing!
评论 #42676787 未加载
amelius4 个月前
Sometimes, only a specific wheel is available (e.g. on Nvidia&#x27;s Jetson platform where versions are dictated by the vendor).<p>Can uv work with that?
fire_lake4 个月前
Even better would be if you could specify the dependencies inside of the script.<p>Edit: might be possible now? <a href="https:&#x2F;&#x2F;simonwillison.net&#x2F;2024&#x2F;Dec&#x2F;19&#x2F;one-shot-python-tools&#x2F;" rel="nofollow">https:&#x2F;&#x2F;simonwillison.net&#x2F;2024&#x2F;Dec&#x2F;19&#x2F;one-shot-python-tools&#x2F;</a>
misiek084 个月前
Small misorder in the „right route” - you should first activate the virtual environment just created and then install pandas.
yangman4 个月前
uv implements PEP 723.<p><a href="https:&#x2F;&#x2F;packaging.python.org&#x2F;en&#x2F;latest&#x2F;specifications&#x2F;inline-script-metadata&#x2F;" rel="nofollow">https:&#x2F;&#x2F;packaging.python.org&#x2F;en&#x2F;latest&#x2F;specifications&#x2F;inline...</a><p>Especially useful if the script has dependencies on packages in private repos.
ErikBjare4 个月前
I really thought this would mention uv script deps (standardized by some PEP) together with a `#!&#x2F;usr&#x2F;bin&#x2F;env -S uv run` shebang line which automatically install the deps on execution.<p>Has been super useful to write single-file tools&#x2F;scripts which LLMs can understand and run easily.
mgd0204 个月前
Whats the point if you have other binary dependencies?<p>Use Nix for Python version as well as other bin deps, and virtualenv + pip-tools for correct package dependency resolution.<p>Waiting 4s for pip-tools instead of 1ms for uv doesn&#x27;t change much if you only run it once a month.
faizshah4 个月前
I love this, the biggest problem I have right now with python scripts is distributing my single file utility scripts (random ops scripts).<p>I wish there was a way to either shebang something like this or build a wheel that has the full venv inside.
评论 #42676896 未加载
评论 #42676954 未加载
评论 #42676887 未加载
评论 #42677230 未加载
vietvu4 个月前
I used to have pyenv, asdf or mise to manage python versions (never use conda unless I need DL lib like pytorch). Now just uv is enough.
crispyambulance4 个月前
I do like uv and hope to try it soon but I don&#x27;t get the point of the article.<p>Pyenv + poetry already gives you ability to &quot;pull in local dependencies&quot;. Yes, you have to create a virtual environment and it&#x27;s not &quot;ad-hoc&quot;.<p>But if you&#x27;re going to pull in a bunch of libraries, WHY would you want to invoke python and all your work dependencies on a one liner? Isn&#x27;t it much better and easier to just spell-out the dependencies in a pyproject.toml? How &quot;ad-hoc&quot; are we talking here?
评论 #42680722 未加载
m3kw94 个月前
That’s like a killer app type feature. However it says adhoc so you probably can’t get back to that setup easily
laidoffamazon4 个月前
I honestly really hate the venv ergonomics but uv does still depend on it as the golden path if you don’t use the —with flags (in my understanding). Is there a way to do a clean break with just the new —script inline dependencies, or is that wrong&#x2F;suboptimal?
评论 #42677560 未加载
sonium4 个月前
But I still need pip to install uv, right? Or download it using a one-liner alternatively.
评论 #42677678 未加载
评论 #42679677 未加载
aizk4 个月前
one useful UV alias I use is uvsys=&#x27;uv pip install --system&#x27;<p>So I can just do uv {package} for a quick and dirty global install. I&#x27;m so used to pip install being global by default just making this shorthand makes things a bit easier.
评论 #42680731 未加载
valcron10004 个月前
Can you also specify which version of pandas to use?
评论 #42677650 未加载
curiousgal4 个月前
uv has does not (nor do they plan to add) support for conda, and that is a deal-breaker.
评论 #42677096 未加载
评论 #42677116 未加载
评论 #42677278 未加载
评论 #42677052 未加载
dang4 个月前
I&#x27;ve replaced the linkbait title with an attempt at saying what the feature is. If there&#x27;s a more accurate wording, we can change it again.
评论 #42677552 未加载
评论 #42676839 未加载
instig0074 个月前
wow, they&#x27;ve re-invented a tiny bit of Nix, purely legend!
评论 #42676783 未加载
评论 #42677091 未加载
评论 #42677748 未加载