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 環境構築 【Windows】

0
Posted at

1. uv をインストール

PowerShell を開いて、以下のコマンドを実行する。

winget install --id=astral-sh.uv -e

インストールが終わったら、PowerShell を一度閉じて開き直す

うまくいかない場合

winget が使えない、またはエラーが出る場合は以下を試す。

powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

こちらも終わったら PowerShell を閉じて開き直す。

2. 動作確認

新しく開いた PowerShell で以下を実行。

uv --version

uv 0.x.x のようにバージョンが表示されれば OK。

3. プロジェクトを作成

作業用のフォルダを作りたい場所に移動する。例としてデスクトップに作る場合。

cd Desktop

hello という名前でプロジェクトを作成。

uv init hello

作成したフォルダに移動。

cd hello

中身を確認。

dir

main.pypyproject.toml があれば OK。

4. Python ファイルを実行

自動で作られた main.py を実行する。

uv run main.py

Hello from hello! と表示されれば OK。

初回実行時は Python 本体のダウンロードが走るため、少し時間がかかる。

5. パッケージを追加

外部ライブラリを使いたい時は uv add で追加する。例として requests を入れてみる。

uv add requests

main.py を以下に書き換えて動作確認。

import requests

response = requests.get("https://httpbin.org/get")
print(response.status_code)

実行。

uv run main.py

200 と表示されれば OK。

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?