您是否厌倦了为了控制 Python 环境和依赖项而使用 pip、virtualenv、conda、poetry 和 pyenv 等多个工具?你并不孤单!管理 Python 项目可能会让人感到头疼,尤其是在需要处理各种不同的包管理器和工具的情况下。
输入 uv — 通用 Virtualenv。将其视为一站式包管理器,旨在简化和加速您的 Python 开发过程。
uv 从另一位现代包装管理器 Rye 中汲取灵感,统一了 pip、pip-tools、pyenv、virtualenv 和 Poetry 的最佳功能。 uv 使用 Rust 构建,不仅速度快,而且效率高,简化了从管理依赖项到创建虚拟环境的一切。
简而言之,uv 就是整合。当您可以获得一种统一的体验时,为什么要在多种工具之间切换?它旨在消除 Python 开发中的摩擦,为您提供更一致、更快速的项目管理方式。而且速度还很快!这为动态管理打开了新的大门
uv 最令人兴奋的功能之一是能够直接在 Python 脚本中添加依赖项。想象一下你有一个像这样的简单脚本:
# app.py import requests from rich.pretty import pprint response = requests.get("https://peps.python.org/api/peps.json") data = response.json() pprint([(k, v["title"]) for k, v in data.items()][:10])
运行此脚本通常意味着设置虚拟环境并手动安装依赖项。使用 uv,您可以将所有依赖项直接嵌入到脚本中,使其自包含和可共享:
$ uv add --script app.py 'requests422dfd12375daf3b128a81a7d42c5b48=1.10.0' "git+https://github.com/astral-sh/ruff"
No more waiting around for slow installations—uv gets the job done fast and effectively.
Whether you're linting code or formatting files, uv makes installing CLI tools easy:
Globally:
$ uv tool install ruff
Locally within a Project:
$ uv add ruff
Run Ephemeral Commands without Installing Globally:
$ uvx black my_code.py
Say goodbye to package conflicts and environment pollution—just run your tools whenever and wherever you need them.
If you're looking to supercharge your Python development and want to stop wrestling with multiple tools, uv is your answer. With its streamlined commands, reproducible environments, and efficient package management, uv makes Python development a pleasure rather than a chore.
Ready to take uv for a spin? ? Start today and experience a better way to manage your Python projects.
Stay tuned for Part 2, where we'll dive deeper into advanced features like leveraging pyproject.toml, handling global vs. local tool installations, and how uv can be your best friend when managing complex environments.
Happy coding! ?✨
For more details and full documentation, check out uv documentation.
以上是使用 uv 掌握 Python 项目管理 PartIts Time to Ditch Poetry的详细内容。更多信息请关注PHP中文网其他相关文章!