0
2

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備忘録

0
Posted at

公式HP:
https://docs.astral.sh/uv

Python環境管理ツール。

  • PythonのバージョンとPythonのライブラリーの両方をプロジェクトベースで(pyproject.toml)管理できる
  • npmのようにプロジェクトごとに環境を作成
  • Rust製で高速

インストール

curl -LsSf https://astral.sh/uv/install.sh | sh

pythonのインストール

uv python install 3.11

pythonバージョンの固定

uv python pin 3.11

環境作成

uv init {project}
# または、すでにフォルダがある場合
uv init

アクティベート

source .venv/bin/activate

ライブラリー追加

uv add requests
uv add 'requests==2.31.0'
uv add requests --git https://github.com/psf/requests

削除時は

uv remove requests

特殊なケース

C Compilerエラーでコケる場合(uvwsgiなど)

export LDFLAGS=~/.local/share/uv/python/cpython-3.11.10-linux-x86_64-gnu/lib/libpython3.so
export LD_LIBRARY_PATH=~/.local/share/uv/python/cpython-3.11.10-linux-x86_64-gnu/lib/libpython3.so
uv add uwsgi

uwsgiは他にも、uvをアップデートしたり、pythonのマイクロバージョンを調整したりするとインストールできる場合がある。

全ライブラリーのインストール

pyproject.tomlから全パッケージをインストールするには、プロジェクトのディレクトリに移動し、以下を実行。

uv sync

環境がない場合でも自動で環境が作成されてパッケージがインストールされる。

0
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?