Closed3

rye 使ってみた

jimiijimii

セットアップ

https://rye-up.com/guide/installation/

インストール

brew install rye

バージョン確認

rye --version
rye 0.30.0
commit: 0.30.0 (2024-03-19)
platform: macos (aarch64)
self-python: not bootstrapped (target: cpython@3.12)
symlink support: true
uv enabled: false
jimiijimii

プロジェクトの作成

初期化

rye init time-design-backend
success: Initialized project in /Users/onishis/Repositories/private/time-design-backend
  Run `rye sync` to get started

ディレクトリ構成

tree
.
├── README.md
├── pyproject.toml
└── src
    └── time_design_backend
        └── __init__.py

Pythonバージョン指定

rye pin 3.12

cat .python-version
# 3.12.2
jimiijimii

sync

rye sync
error: virtualenv is not managed by rye. Run `rye sync -f` to force.
rye sync -f
Forcing re-creation of non-rye managed virtualenv
Initializing new virtualenv in /Users/hoge/Repositories/private/time-design-backend/.venv
Python version: cpython@3.12.2
error: failed creating virtualenv ahead of sync

Caused by:
    0: unable to invoke virtualenv command
    1: No such file or directory (os error 2)

仮想環境の作成に失敗するエラーが発生。

とりあえずヘルプみるかと思ってryeだけ打った

rye
Welcome to Rye!

Rye has detected that it's not installed on this computer yet and
automatically started the installer for you. For more information
read https://rye-up.com/guide/installation/

This installer will install rye to /Users/hoge/.rye
This path can be changed by exporting the RYE_HOME environment variable.

Details:
  Rye Version: 0.30.0
  Platform: macos (aarch64)

✔ Continue? · yes
✔ Select the preferred package installer · pip-tools (slow but stable)
✔ 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/hoge/.rye/shims/rye
Updated self-python installation at /Users/hoge/.rye/self

The rye directory /Users/hoge/.rye/shims was not detected on PATH.
It is highly recommended that you add it.
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!

? rye を実行すると初回インストール時の表示がされた。設定すればいけるか?
→結果変わらず。色々試した(詳細忘れた)けど、rye add, rye update などなにやっても同じくエラー。

再インストールしても結果変わらず。(brew uninstall rye -> brew install rye)

ダメ元で、brewでのインストールではなくcurlのでインストールし直してみた。
→だめ。

curlで入れたのはアンインストールして、再度brewで入れ直した。
無理だったーと思って、再度症状確認しようとしてプロジェクト作って試すと

rye init test
success: Initialized project in /Users/hoge/Repositories/private/test
  Run `rye sync` to get started
  
rye sync
Initializing new virtualenv in /Users/hoge/Repositories/private/test/.venv
Python version: cpython@3.12.2
Generating production lockfile: /Users/hoge/Repositories/private/test/requirements.lock
Creating virtualenv for pip-tools
Generating dev lockfile: /Users/hoge/Repositories/private/test/requirements-dev.lock
Installing dependencies
Looking in indexes: https://pypi.org/simple/
Obtaining file:///. (from -r /var/folders/zp/zrsp7mx179vbp2ybw7whvmjm0000gq/T/tmpkpkxeyh0 (line 1))
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... done
  Installing backend dependencies ... done
  Preparing editable metadata (pyproject.toml) ... done
Building wheels for collected packages: test
  Building editable for test (pyproject.toml) ... done
  Created wheel for test: filename=test-0.1.0-py3-none-any.whl size=1004 sha256=4c27d1f576dd7228f1a98d4dc7933892464600b88b6968f9a68e74c163d42001
  Stored in directory: /private/var/folders/zp/zrsp7mx179vbp2ybw7whvmjm0000gq/T/pip-ephem-wheel-cache-tfs_z54h/wheels/8b/19/c8/73a63a20645e0f1ed9aae9dd5d459f0f7ad2332bb27cba6c0f
Successfully built test
Installing collected packages: test
Successfully installed test-0.1.0
Done!

!!?! いけた

よくわかんないけど解決するという最低なパターン。
おそらく、初回エラー発生時にvirtualenv入れ直したり、パスを通したり、rye addで怒られたからunearthを入れたりとかしてたらへんが関係してるかもしれない。
けど、一旦はいいや

このスクラップは3ヶ月前にクローズされました