概要
以前にPythonの開発環境にryeを乗り換えたところ、uvに対応していたのでインストールしてみました。
環境
用語
rye
公式の文章になりますが、Pythonでパッケージ管理だけでなく、プロジェクト管理も行うためのツールになります。
元々はRust
におけるcargo
のように、プロジェクト毎にインストールされているパッケージをPythonでも管理したいという思いから作られています。
pyenvとの違い
例えば、pyenv
と比較するとpyenv
では先に仮想環境を作成して、次にプロジェクトごと(フォルダごと)にプログラムを実行します。
そのために該当のプロジェクトでプログラムを実行する場合は
該当の仮想環境に切り替える(例:pythonのバージョンは3.10、パッケージモジュールは⚪︎⚪︎など)
プロジェクト(フォルダ)に移動
プログラムを実行
という手順になります。
そのために該当のプロジェクトでプログラムを実行しようとすると仮想環境を切り替えて実行する必要があります。
一方で、Rye
でプロジェクト管理するとプロジェクトごと(フォルダごと)に必要なパッケージやプログラムのバージョンなども管理できるため、
プロジェクト(フォルダ)に移動
プログラムを実行
で実行することができます。
uv
こちらも、公式の文章になりますが、Rust
で実行されているPythonモジュールのインストーラであり、pip
でパッケージをインストールするよりも高速です。
方法
Ryeのバージョンをチェック
下記より、0.11.0
であることが分かります。
対応しているバージョンは0.24.0
以上なので、アップデートする必要があります。
% rye --version rye 0.11.0 commit: 0.11.0 (f6f63d6c1 2023-07-18) platform: macos (x86_64) self-python: cpython@3.11 symlink support: true
Ryeのバージョンのアップデート
下記のrye self update
コマンドを実行して、バージョンをアップデート。
ただし、このままだとuv enabled: false
の通り、uv
は使えていないので、設定でtrue
に変更します。
% rye self update Updating to latest Checking checksum Updated! rye 0.33.0 commit: 0.33.0 (58523f69f 2024-04-24) platform: macos (x86_64) self-python: not bootstrapped (target: cpython@3.12) symlink support: true uv enabled: false
uvを使えるように変更
公式を参考に下記のコマンドを実行。
% rye config --set-bool behavior.use-uv=true
次にホームディレクトリにあるconfig.toml
に設定されているか確認します。
% rye config --show-path ホームディレクトリ/.rye/config.toml % cat ホームディレクトリ/.rye/config.toml [behavior] use-uv = true
下記のようにuse-uv = true
となっていれば、OKです。
[behavior] use-uv = true
再度、rye self update
を実行します。
% rye self update Updating to latest Checking checksum Validate updated installation Detected outdated rye internals. Refreshing Bootstrapping rye internals Found a compatible Python version: cpython@3.11.3 Initializing new virtualenv in /private/var/folders/gf/5ntllx1s5wjdw2945t44f45w0000gn/T/.tmpopChOT/.venv Python version: cpython@3.11.3 Updated! rye 0.33.0 commit: 0.33.0 (58523f69f 2024-04-24) platform: macos (x86_64) self-python: cpython@3.11.3 symlink support: true uv enabled: true
uv enabled: true
となっていれば、uv
を利用できるようになります。
動作確認
uv
が使えるようになっているか確認します。
% rye --version rye 0.33.0 commit: 0.33.0 (58523f69f 2024-04-24) platform: macos (aarch64) self-python: cpython@3.11.3 symlink support: true uv enabled: true % rye init test-uv-enable success: Initialized project in /test-uv-enable Run `rye sync` to get started % cd test-uv-enable % rye add flask Added flask>=3.0.3 as regular dependency % rye add pandas Added pandas>=2.0.3 as regular dependency % time rye sync Reusing already existing virtualenv Generating production lockfile: /test-uv-enable/requirements.lock Generating dev lockfile: /test-uv-enable/requirements-dev.lock Installing dependencies Installed 16 packages in 26ms + blinker==1.8.1 + click==8.1.7 + flask==3.0.3 + importlib-metadata==7.1.0 + itsdangerous==2.2.0 + jinja2==3.1.3 + markupsafe==2.1.5 + numpy==1.24.4 + pandas==2.0.3 + python-dateutil==2.9.0.post0 + pytz==2024.1 + six==1.16.0 + tzdata==2024.1 + werkzeug==3.0.2 + zipp==3.18.1 Done! rye sync 0.43s user 0.21s system 101% cpu 0.629 total