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?

uv による python パッケージの管理

Posted at

uv とは

Rust で記述された python の高速なパッケージマネージャ。
uv run で python スクリプトを実行することができる。

$ uv run python {script.py}

uv のインストール

以下を実行すると、~/.local/bin に uv がインストールされる。

$ curl -LsSf https://astral.sh/uv/install.sh | sh
$ which uv
/.local/bin/uv

python のインストール

uv python install で python をインストールする。

$ uv python install 3.12.12
$ uv run python --version
Python 3.12.12

uv の使い方

プログラムの実行

$ uv run python {script.py}

プロジェクトの初期化

$ uv init {project}
$ uv init test-project
$ tree test-project
test-project
├── README.md
├── main.py
└── pyproject.toml

パッケージのインストール

uv init で作成したプロジェクトディレクトリに移動し、uv add でパッケージをインストールする。

$ uv add {package}

パッケージをインストールすると uv.lock が作成される。

[test-project]$ tree
.
├── README.md
├── main.py
├── pyproject.toml
└── uv.lock

パッケージの一覧

$ uv pip list
[test-project]$ uv pip list
Package   Version
--------- -------
iniconfig 2.3.0
packaging 25.0
pluggy    1.6.0
pygments  2.19.2
pytest    9.0.2

パッケージのインストール

以下で pyproject.toml に記述されたパッケージをインストールできる。

$ uv pip install -r pyproject.toml
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?