はじめてのuv
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
-c "irm https://astral.sh/uv/install.ps1 | iex" powershell
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)"