首頁  >  文章  >  後端開發  >  使用 uv 掌握 Python 專案管理 PartIt&#s Time to Ditch Poetry

使用 uv 掌握 Python 專案管理 PartIt&#s Time to Ditch Poetry

Barbara Streisand
Barbara Streisand原創
2024-09-30 06:16:02868瀏覽

Mastering Python Project Management with uv PartIt

您是否厭倦了為了控制 Python 環境和依賴項而使用 pip、virtualenv、conda、poetry 和 pyenv 等多個工具?你並不孤單!管理 Python 專案可能會讓人感到頭疼,尤其是在需要處理各種不同的套件管理器和工具的情況下。

輸入 uv通用 Virtualenv。將其視為一站式套件管理器,旨在簡化和加速您的 Python 開發流程。


一些背景故事

uv 從另一個現代包裝管理器 Rye 汲取靈感,統一了 pip、pip-tools、pyenv、virtualenv 和 Poetry 的最佳功能。 uv 使用 Rust 構建,不僅速度快,而且效率高,簡化了從管理依賴項到創建虛擬環境的一切。

紫外線的目的

簡而言之,uv 就是整合。當您可以獲得一種統一的體驗時,為什麼要在多種工具之間切換?它旨在消除 Python 開發中的摩擦,為您提供更一致、更快速的專案管理方式。而且速度還很快!這為動態管理開啟了新的大門


1. 具有內嵌腳本元資料的可移植程式碼

讓我們談談依賴關係

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 'requestsf4261151f834235b143f7c286ab34f72=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.


6. Manage CLI Tools Globally and Easily

From black to ruff, Get Your Tools Hassle-Free

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 專案管理 PartIt&#s Time to Ditch Poetry的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn