LoginSignup
0
0

Pythonの管理にRyeをおすすめしたい

Last updated at Posted at 2024-04-18

Linux上でPythonをインストールするのってめっちゃ面倒くさいですよね。
Ryeを使えばPythonのインストールからバージョンの管理・変更、パッケージ管理がノンストレスでできちゃう!

Ryeって何( 簡単に )

RyeはPython用の包括的なプロジェクトおよびパッケージ管理ツール。Pythonのインストール、プロジェクト・依存関係・仮想環境の管理を爆速で統合的に行える。

インストール方法

Linuxにおいてのインストール方法。
以下を実行するだけ Installation - Rye (rye-up.com)

curl -sSf https://rye-up.com/get | bash

尋問される

インストール過程でいくつか質問される。

? What should running `python` or `python3` do when you are not inside a Rye managed project? › 
❯ Run a Python installed and managed by Rye 
  Run the old default Python (provided by your OS, pyenv, etc.)

Ryeに完全に移行したいなら前者、既にシステム内にPythonを使ったプログラムがあるなら後者、悩んだら後者を選ぶほうがセーフティ知らんけど、

? Which version of Python should be used as default toolchain? (cpython@3.12)

どうせ後々バージョン変更できるから、適当に入れておこう。(それするためのRyeやしね)

Rye自身のアップデートは以下。

rye self update

使い方

プロジェクトの設定

新しいプロジェクトを作る。

rye init <PROJECT_NAME>

既存のディレクトリでやりたいときは

rye init

でも可

Pythonのバージョンを指定する。

rye pin <PYTHON_VERSION>

設定を反映させる。パッケージの変更のたびに実行する必要がある。

rye sync

任意のバージョンのpythonをインストールする方法

インストール可能なバージョン一覧の表示

rye toolchain list --include-downloadable

インストール

rye toolchain fetch <SUKINAYATU>

pinコマンド実行

rye pin <<SUKINAYATU>>

設定を反映させる。

rye syn

仮想環境の実行

仮想環境の実行は

source .venv/bin/activate

これだけ。

ファイルの実行

rye run python <FILE_NAME>.py

仮想環境の終了

deactivate
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