安装virtualenv和mkvirtualenv-win之后,在Scripts文件夹中添加workon.ps1文件,内容如下
$WORKON_HOME="C:\Python\Envs\" # Path to your Envs folder
$ENV = $args[0] # ignore all other args
if ($ENV) {
$PATH = $WORKON_HOME+$ENV
if ((Test-Path $PATH) -eq "True") {
Invoke-Expression "$PATH\Scripts\activate.ps1"
}
else {
Write-Host("doesn't contain a virtualenv")
Write-Host("Create it with 'mkvirtualenv' $ENV")
}
}
else {
Write-Host("Pass a name to activate one of the following virtualenvs:")
Write-Host("==============================================================================")
Get-ChildItem $WORKON_HOME | ForEach-Object -Process {
Write-Host($_.name)
}
}