Closed5
Python実行環境をRyeで構築する
ドキュメント
インストール
curl -sSf https://rye-up.com/get | bash
This script will automatically download and install rye (latest) for you.
######################################################################## 100.0%
Welcome to Rye!
This installer will install rye to /Users/xxxx/.rye
This path can be changed by exporting the RYE_HOME environment variable.
Details:
Rye Version: 0.32.0
Platform: macos (aarch64)
✔ Continue? · yes
✔ Select the preferred package installer · uv (fast, recommended)
✔ What should running `python` or `python3` do when you are not inside a Rye managed project? · Run a Python installed and managed by Rye
✔ Which version of Python should be used as default toolchain? · cpython@3.12
Installed binary to /Users/xxxx/.rye/shims/rye
Bootstrapping rye internals
Downloading cpython@3.12.2
Checking checksum
Unpacking
Downloaded cpython@3.12.2
Updated self-python installation at /Users/xxxx/.rye/self
The rye directory /Users/xxxx/.rye/shims was not detected on PATH.
It is highly recommended that you add it.
✔ Should the installer add Rye to PATH via .profile? · yes
Added to PATH.
note: for this to take effect you will need to restart your shell or run this manually:
source "$HOME/.rye/env"
To make it work with zsh, you might need to add this to your .zprofile:
source "$HOME/.rye/env"
For more information read https://rye-up.com/guide/installation/
All done!
zsh
を使っているので、以下の手順を実行。
To make it work with zsh, you might need to add this to your .zprofile:
echo 'source "$HOME/.rye/env"' >> ~/.zprofile
プロジェクトの作成
以下を参考にプロジェクトを作成する。
rye init my-project
以下の構成のプロジェクトが作成される。
.
├── .git
├── .gitignore
├── .python-version
├── README.md
├── pyproject.toml
└── src
└── my_project
└── __init__.py
rye sync
を実行する。
.venv
ディレクトリとrequirements.lock
、requirements-dev.lock
ファイルが作成される。
ライブラリの追加
以下のコマンドでライブラリを追加。
rye add flask
pyproject.toml
、requirements.lock
、requirements-dev.lock
にflaskが追加される。
Dockerでの実行
ドキュメントを参考に、Dockerで動作させる。
pyproject.toml
の[tool.rye]
のセクションの下にvirtual = true
を追加。
rye sync
を実行。
requirements.lock
、requirements-dev.lock
に以下の差分が発生する。
これでビルド時にパッケージのインストールが可能となる。
requirements.lock
--e file:.
blinker==1.7.0
# via flask
click==8.1.7
# via flask
flask==3.0.3
- # via my-project
itsdangerous==2.2.0
# via flask
jinja2==3.1.3
Pythonのバージョンを変更
Ryeで管理しているバージョンの確認
rye toolchain list
3.12.4をダウンロードしようとしたところ下記のエラーになった
rye fetch 3.12.4
error: error while fetching Python installation
Caused by:
unknown version 3.12.4
rye自体のバージョンをアップデート
rye self update
3.12.4を再度ダウンロードし成功
rye fetch 3.12.4
.python-version
を変更する
.python-version
3.12.4
以下のコマンド実行
rye sync
バージョン確認
rye run python --version
Python 3.12.4
このスクラップは2024/09/26にクローズされました