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の仮想環境を作成する

Posted at

Pythonの練習をするために仮想環境を作成した時の手順

前提

macOS + HomebrewでPython 3.13をインストール済みであること

流れ

1. Pythonのフォルダ内でpython3 -m venv venv を実行する。

python3 -m venv venv

python3 -m venv myenv というように書くなど、ディレクトリ名は自由

実行すると以下のように新しくvenvフォルダが作成される。

スクリーンショット 2025-07-29 11.48.51.png
※実際の開発ではvenvをgitignoreに入れておくことが好ましい

2. source venv/bin/activate を実行する。

source venv/bin/activate

実行することで仮想環境が有効化され、ターミナルの表示に(venv)の表示が出てくる。

(venv) noukin@noukinnnn Pythonscraping %

この状態になれば自由に記述できる。

3. ファイル名がscraper.py の場合、python scraper.pyと記述して実行。

python scraper.py

※macの場合、古いバージョンのPythonが入っている可能性があるのでpython3 scraper.py というように記述することが実は好ましい模様。

仮想環境を終了する時

以下を実行すると抜ける。

deactivate
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?