0
1

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

1. Python仮想環境を作成する

python -m venv env
  • env は仮想環境のフォルダ名(例:.venv, myenv などお好みで)

2. 仮想環境に入る(アクティベート)

✅ macOS / Linux の場合:

source env/bin/activate

✅ Windows の場合:

.\env\Scripts\activate
  • 入るとプロンプトが (env) のように変わる
    例:(env) user@pc project %

3. 仮想環境内でパッケージをインストール

pip install パッケージ名
  • 例:pip install numpy
  • 他のプロジェクトには影響しません。

4. 仮想環境から抜ける(ディアクティベート)

deactivate

5. よく使う補助コマンド

内容 コマンド
インストール済み一覧を見る pip list
パッケージ情報をファイルに出力 pip freeze > requirements.txt
ファイルから一括インストール pip install -r requirements.txt

💡 補足:おすすめの使い方スタイル

# 1. プロジェクトディレクトリで仮想環境を作成
python -m venv env

# 2. 仮想環境に入る
source env/bin/activate  # Windowsなら .venv\Scripts\activate

# 3. 必要なパッケージをインストール
pip install -r requirements.txt
  • .venv.gitignore に追加して、Git管理から除外するのが一般的です。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?