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

0
Posted at

1. Homebrew をインストール

ターミナルを開いて、以下のコマンドを実行する。

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

途中で パスワードを求められたら、Mac のログインパスワードを入力(画面には表示されないが、入力はされている)。

インストールが終わったら、画面の最後に表示される 「Next steps:」 の中の 2 つのコマンドをコピーして実行する。これで Homebrew に PATH を通せる。

動作確認。

brew --version

Homebrew 4.x.x のように表示されれば OK。

すでに Homebrew が入っている人はこの手順はスキップして良い。

2. uv をインストール

brew install uv

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

3. 動作確認

新しく開いたターミナルで以下を実行。

uv --version

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

4. プロジェクトを作成

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

cd ~/Desktop

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

uv init hello

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

cd hello

中身を確認。

ls

main.pypyproject.toml があれば OK。

5. Python ファイルを実行

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

uv run main.py

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

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

6. パッケージを追加

外部ライブラリを使いたい時は 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?