LoginSignup
2
3

More than 3 years have passed since last update.

Python: 仮想環境作成(venv)・起動・停止まで

Last updated at Posted at 2020-10-04

使用環境

macOS Catalina

目次

venvを使ってpython仮想環境を作る

・仮想環境上で〇〇.pyファイルを実行

python仮想環境を作る

===仮想環境myPythonを作成、仮想環境の起動・停止まで===

・Pythonの仮想環境を作成したいディレクトリに移動

cd /Users/tanaka/Downloads/

・仮想環境を作成

python3.8 -m venv myPython

[補足] /Users/tanaka/Downloads/配下に、仮想環境myPythonがされています。

・仮想環境へ移動

cd myPython

・仮想環境を起動

source bin/activate

・パッケージをインストール

pip install requests

[補足]pip install [パッケージ名]

・インストールされたパッケージリストを確認

pip freeze

・インストールしたパッケージ毎の詳細情報を表示

pip show requests

・仮想環境を閉じる

deactivate

仮想環境上で.pyファイルを実行

・ターミナル上に実行したい.pyファイルをドラック&ドロップして実行

python3.8 /Users/tanaka/Downloads/myPython/main.py 

[補足]ターミナルでpython3.8と入力後、ターミナルにmain.pyファイルをドラック&ドロップ

[おわり]

2
3
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
2
3