Skip to content

Instantly share code, notes, and snippets.

@laughk
Last active April 19, 2021 01:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laughk/34e74bfc868c85c7105f54807c29006f to your computer and use it in GitHub Desktop.
Save laughk/34e74bfc868c85c7105f54807c29006f to your computer and use it in GitHub Desktop.
Windows ( PowerShell ) で venv メモ

Windows で venv

事前準備 (PowerShell の実行ポリシーの確認と設定)

PowerShell の場合、 実行ポリシーが規定の設定の Restricted の場合はスクリプトが実行できないためactivate できません。 そのため、venv を有効化する際に必要なスクリプトの実行ができるように実行ポリシーを変更する必要があります。

現状の実行ポリシーの確認 (デフォルトでは Undefined になっているはず。)

PS: > Get-ExecutionPolicy -Scope CurrentUser
Undefined 

RemoteSigned に変更する

PS: > Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser RemoteSigned

対話画面で変更してもよいかを聞かれるので、[Y] で変更に同意する。

image

PowerShell の実行ポリシーについての詳細はこちら

venv の作成

PS: > python -m venv venv
PS: >

仮想環境の有効化

PS: > .\venv\Scripts\activate
(venv) PS: > 

仮想環境から抜ける(無効化)

(venv) PS: > deactivate
PS: >

[おまけ] C:\Users\laughk\Documents\sample で venv の有効化とか

image

@laughk
Copy link
Author

laughk commented Jul 23, 2017

画像アップロード用コメント

image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment