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?

Python環境の基本とuvの使い方

Posted at

Pythonを動かすために必要な3要素

  • Python本体:コードを実行するプログラムそのもの
  • 仮想環境:プロジェクトごとに独立した環境
  • パッケージ管理:外部ライブラリを入れる仕組み(pipなど)

従来の方法(手動で環境構築)

python -m venv .venv
source .venv/bin/activate
pip install fastapi
  • .venv を作って環境を分ける
  • activate でその環境を有効化
  • pip install でライブラリを入れる

uvを使う方法(自動で環境構築)

uv init .
uv add fastapi
  • uv init .:プロジェクト設定ファイル(pyproject.toml)を作成
  • uv add fastapi:仮想環境を自動で作成し、ライブラリをインストール

まとめ

やりたいこと 従来の方法 uvの方法
環境作成 python -m venv .venv 自動(uv add
有効化 source .venv/bin/activate 不要
依存追加 pip install fastapi uv add fastapi

覚えておくことは1つだけ。

uvは「仮想環境の作成」「有効化」「pip install」を全部自動でやってくれる。

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?