Open1

Rye で Python バージョン管理 - WSL Ubuntu 24.04 LST

kikudaikikudai

Rye インストール

# 対話なしでインストール
curl -sSf https://rye.astral.sh/get | RYE_VERSION="0.41.0" RYE_INSTALL_OPTION="--yes" bash

echo 'source "$HOME/.rye/env"' >> ~/.bashrc
mkdir -p ~/.local/share/bash-completion/completions
rye self completion > ~/.local/share/bash-completion/completions/rye.bash

# rye 再進化
rye self update

# グローバル設定
rye config --set-bool behavior.global-python=true

# グローバルpython 3.10 切り替え
rye pin 3.10
rye fetch

python --version

Pythonプロジェクトの構築

rye init my-project
cd my-project
rye pin 3.12
rye sync

# 仮想環境有効化
. .venv/bin/activate

# 仮想環境無効化
deactivate

参考

https://rye.astral.sh/guide/installation/
https://rye.astral.sh/guide/shims/#global-shims