1
1
<#
2
2
. Synopsis
3
- Activate a Python virtual environment for the current Powershell session.
3
+ Activate a Python virtual environment for the current PowerShell session.
4
4
5
5
. Description
6
6
Pushes the python executable for a virtual environment to the front of the
@@ -37,6 +37,15 @@ Activates the Python virtual environment that contains the Activate.ps1 script,
37
37
and prefixes the current prompt with the specified string (surrounded in
38
38
parentheses) while the virtual environment is active.
39
39
40
+ . Notes
41
+ On Windows, it may be required to enable this Activate.ps1 script by setting the
42
+ execution policy for the user. You can do this by issuing the following PowerShell
43
+ command:
44
+
45
+ PS C:\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
46
+
47
+ For more information on Execution Policies:
48
+ ttps:/go.microsoft.com/fwlink/?LinkID=135170
40
49
41
50
#>
42
51
Param (
@@ -137,7 +146,7 @@ function Get-PyVenvConfig(
137
146
$val = $keyval [1 ]
138
147
139
148
# Remove extraneous quotations around a string value.
140
- if (" '"" " .Contains($val.Substring (0 , 1 ))) {
149
+ if (" '"" " .Contains($val.Substring (0 , 1 ))) {
141
150
$val = $val.Substring (1 , $val.Length - 2 )
142
151
}
143
152
@@ -165,7 +174,8 @@ Write-Verbose "VenvExecDir Name: '$($VenvExecDir.Name)"
165
174
# VenvExecDir if specified on the command line.
166
175
if ($VenvDir ) {
167
176
Write-Verbose " VenvDir given as parameter, using '$VenvDir ' to determine values"
168
- } else {
177
+ }
178
+ else {
169
179
Write-Verbose " VenvDir not given as a parameter, using parent directory name as VenvDir."
170
180
$VenvDir = $VenvExecDir.Parent.FullName.TrimEnd (" \\/" )
171
181
Write-Verbose " VenvDir=$VenvDir "
@@ -179,7 +189,8 @@ $pyvenvCfg = Get-PyVenvConfig -ConfigDir $VenvDir
179
189
# just use the name of the virtual environment folder.
180
190
if ($Prompt ) {
181
191
Write-Verbose " Prompt specified as argument, using '$Prompt '"
182
- } else {
192
+ }
193
+ else {
183
194
Write-Verbose " Prompt not specified as argument to script, checking pyvenv.cfg value"
184
195
if ($pyvenvCfg -and $pyvenvCfg [' prompt' ]) {
185
196
Write-Verbose " Setting based on value in pyvenv.cfg='$ ( $pyvenvCfg [' prompt' ]) '"
0 commit comments