0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

rye に切り替える..

Posted at

venv でも行けなくはないが・・・

パッケージが管理できてない・・・

rye の存在を知る

Pythonの開発環境の3つの観点をおさえよう より。

Python の開発環境構築の、本当に初歩の初歩としては「pyenv などを使わずになんとなく Python をインストールして、仮想環境なしで pip を使う」ことだと思います

遊んでいるうちは良かったのですが、ubuntuの環境は壊れると警告してきて億劫です。 FreeBSDあたりだとpythonのバージョン遅れというか石橋を叩いてる状況だったりで、そんなに苦労はしない(というかpythonセンシブルなコンポーネントは仮想化しています)ので・・・

この記事で注目した 3 つの観点を 1 つのツールで解決できるのが「Rye」です。

新しいものを試して合わなきゃ変えるのもこの時代の生き方。

ubuntu で 苦労したければ、"開発系でapt は使わない"

snapだとコンテナ化されているのでライブラリの不整合で死にません。このことは dpkg を不用意にイジるより選択しておいて良いです。 ubuntuを使うようなライトユーザ1 に dpkgのような鋭い刃物を扱う技量はないということもありますが。

Rye を入れる

Install

curl -sSf https://rye.astral.sh/get | bash

でも良さそうですが、コンパイル行きます。

ubuntu24.10 であっても apt で入りそうな rust は削除して snap から入れておきましょう。 2025年3月時点で 1.80 とかちょっと古いです。

  • sudo してやると問題ないのですが・・・ インストール先が /root/.cargoになってしまう・・
$ sudo cargo install --git https://github.com/astral-sh/rye rye                                                                              Updating git repository `https://github.com/astral-sh/rye`
  Installing rye v0.44.0 (https://github.com/astral-sh/rye#e2139383)
    Updating crates.io index
    Updating git repository `https://github.com/console-rs/dialoguer`
    Updating git repository `https://github.com/konstin/poc-monotrail`
     Locking 328 packages to latest compatible versions
      Adding age v0.10.1 (available: v0.11.1)
      Adding bzip2 v0.4.4 (available: v0.5.2)
      Adding pep440_rs v0.4.0 (available: v0.7.3)
      Adding pep508_rs v0.3.0 (available: v0.9.2)
      Adding which v6.0.3 (available: v7.0.2)
      Adding winreg v0.52.0 (available: v0.55.0)
      Adding zip v0.6.6 (available: v2.5.0)
   Compiling proc-macro2 v1.0.94
   Compiling unicode-ident v1.0.18
   Compiling libc v0.2.171
  • rust/cargo が古いと叱られます。
error: failed to compile `rye v0.44.0 (https://github.com/astral-sh/rye#e2139383)`, intermediate artifacts can be found at `/tmp/cargo-installkDBXjZ`.
To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.

Caused by:
  failed to parse manifest at `/home/hiko/.cargo/registry/src/index.crates.io-6f17d22bba15001f/reword-7.0.1/Cargo.toml`

Caused by:
  feature `edition2024` is required

  The package requires the Cargo feature called `edition2024`, but that feature is not stabilized in this version of Cargo (1.83.0 (5ffbef321 2024-10-29)).
  Consider trying a newer version of Cargo (this may require the nightly release).
  See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#edition-2024 for more information about the status of this feature.

edition2024 が必要といわれてしまいました。cargo fix --edition すればいいとのこと。不安定バージョンを使っていると警告です。

  • rustup で更新しましょう。
    ~/.cargo/bin/ 以下は rustup コマンドで管理。
   Compiling monotrail-utils v0.0.1 (https://github.com/konstin/poc-monotrail?rev=e0251f68c254f834180198b8677fcf85d4b6a844#e0251f68)
    Finished `release` profile [optimized] target(s) in 1m 11s
  Installing /home/hiko/.cargo/bin/rye
   Installed package `rye v0.44.0 (https://github.com/astral-sh/rye#e2139383)` (executable `rye`)

無事に終了。

基本

$ rye init my-project
$ cd my-project
  • .gitignore ができてます。中はこんなです
# python generated files
__pycache__/
*.py[oc]
build/
dist/
wheels/
*.egg-info

# venv
.venv

pyproject.toml、python-version は固有のファイルで新しく入りますが、既存プロジェクトでの .gitignore が新しくならないんで注意(早速イレギュラーをやっている)

  • srcディレクトリがあり、init.py が作られます。 mkdocs のprojectで mkdocs を入れるだけなら要らないかもですが、 eel を入れてアプリとして成長があるなら src以下に入れていくのもありですね。

と、取り敢えずココまでにしておきます。

例によって時間がなくなりました。。。

  1. 私のことだ。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?