WindowsにPython環境をuvで構築
2024-11-11
インストール
Installation | uvuv is an extremely fast Python package and project manager, written in Rust.
docs.astral.sh
公式サイトでは以下のコマンドで紹介されていますが、これは PowerShell 5 以前を想定しているみたいです。
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"一応 PowerShell 7 以降はこちらが標準です。
pwsh -c "irm https://astral.sh/uv/install.ps1 | iex"ただ今回はWingetでインストールを進めます。
winget install --id astral-sh.uvバージョン確認で正常に表示されれば成功です。
uv --version基本的なコマンド
- Python のインストール
uv python install 3.11 3.12- Python ファイルの実行
uv run example.py- 依存関係の追加
uv add [名称]- 依存関係の削除
uv remove [名称]- プロジェクトの作成
uv init- バージョンの固定
uv python pin 3.12.7- venv 作成
uv venv- 仮想環境アクティベート
.venv\Scripts\activate- 仮想環境無効化
deactivateおわり
もともとpyenv+poetryで使用しましたが、uv1 つになったことでコマンド操作が楽になりました。
uvの動作も早いため結構快適に使えています。