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 venvとは

Posted at

venvとは

venv は 仮想環境(Virtual Environment)を作る仕組み です。
・プロジェクトごとに Python 実行環境を分けられる
・インストールするライブラリもプロジェクト単位で管理可能
・システム全体の Python 環境を汚さずに済む

使い方

python -m venv venv

venv はフォルダ名(任意)
この中に Python実行環境とライブラリ管理用フォルダ が作られる

仮想環境を有効化

# windowsの場合
venv\Scripts\active

プロンプトが (venv) のように変わり、仮想環境が有効になったことを示す
この状態で pip install ライブラリ をすると、venv 内にのみインストールされる

仮想環境を無効化

deactivate

venvのメリット

プロジェクトごとの依存関係を分離
・プロジェクトAは requests==2.30
・プロジェクトBは requests==2.28
→ 衝突せず共存可能

システム環境を汚さない
グローバルの Python を上書きしない

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?