はじめてのuv

Author

Ryo Nakagami

Published

2024-11-21

Modified

2024-12-24

Python project managerのuvとは?

uvとはRustで書かれたPython package/project managerのことです.

▶  特徴

  • poetryと類似したコマンドで操作可能
  • poetry add より高速なパッケージインストール
  • pyproject.tomlを用いてパッケージの依存関係,Pythonのバージョンなどのプロジェクトの情報を管理
  • uv.lockというロックファイルにより依存関係を厳密に管理

Installation

▶  with curl

curl -LsSf https://astral.sh/uv/install.sh | sh

▶  with wget

wget -qO- https://astral.sh/uv/install.sh | sh

▶  with curl

curl -LsSf https://astral.sh/uv/install.sh | sh

▶  with wget

wget -qO- https://astral.sh/uv/install.sh | sh

▶  with brew

brew install uv
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
pipx install uv

Ubuntu 24.04 LTS にてcurlを用いてインストールすると,以下のような結果が標準出力されます

% curl -LsSf https://astral.sh/uv/install.sh | sh
downloading uv 0.5.4 x86_64-unknown-linux-gnu
no checksums to verify
installing to /home/ryo_billiken/.local/bin
  uv
  uvx
everything's installed! 

% which uv
/home/hogehoge/.local/bin/uv

% uv version
uv 0.5.4

Uninstallation

rm ~/.local/bin/uv ~/.local/bin/uvx
$ rm $HOME\.local\bin\uv.exe
$ rm $HOME\.local\bin\uvx.exe

▶  cache dataの削除

上記コマンドではuvの実行コマンドを消去しますが,cacheは削除されないのでcacheを削除したい場合は以下のコマンドを実行します

uv cache clean
rm -r "$(uv python dir)"
rm -r "$(uv tool dir)"

Update

2024-11-21段階ではまだ v0.5.4 なので以下のコマンドを用いて頻繁に更新することを推奨します.

uv self update
info: Checking for updates...
success: You're on the latest version of uv (v0.5.4)

Auto-completion Setup

~/.bashrcに以下のラインを記載

# for uv
eval "$(uv generate-shell-completion bash)"

# for uvx
eval "$(uvx --generate-shell-completion bash)"

~/.zshrcに以下のラインを記載

# for uv
eval "$(uv generate-shell-completion zsh)"

# for uvx
eval "$(uvx --generate-shell-completion zsh)"

References