11<#
22. Synopsis
3- Activate a Python virtual environment for the current Powershell session.
3+ Activate a Python virtual environment for the current PowerShell session.
44
55. Description
66Pushes 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,
3737and prefixes the current prompt with the specified string (surrounded in
3838parentheses) while the virtual environment is active.
3939
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
4049
4150#>
4251Param (
@@ -137,7 +146,7 @@ function Get-PyVenvConfig(
137146 $val = $keyval [1 ]
138147
139148 # Remove extraneous quotations around a string value.
140- if (" '"" " .Contains($val.Substring (0 , 1 ))) {
149+ if (" '"" " .Contains($val.Substring (0 , 1 ))) {
141150 $val = $val.Substring (1 , $val.Length - 2 )
142151 }
143152
@@ -165,7 +174,8 @@ Write-Verbose "VenvExecDir Name: '$($VenvExecDir.Name)"
165174# VenvExecDir if specified on the command line.
166175if ($VenvDir ) {
167176 Write-Verbose " VenvDir given as parameter, using '$VenvDir ' to determine values"
168- } else {
177+ }
178+ else {
169179 Write-Verbose " VenvDir not given as a parameter, using parent directory name as VenvDir."
170180 $VenvDir = $VenvExecDir.Parent.FullName.TrimEnd (" \\/" )
171181 Write-Verbose " VenvDir=$VenvDir "
@@ -179,7 +189,8 @@ $pyvenvCfg = Get-PyVenvConfig -ConfigDir $VenvDir
179189# just use the name of the virtual environment folder.
180190if ($Prompt ) {
181191 Write-Verbose " Prompt specified as argument, using '$Prompt '"
182- } else {
192+ }
193+ else {
183194 Write-Verbose " Prompt not specified as argument to script, checking pyvenv.cfg value"
184195 if ($pyvenvCfg -and $pyvenvCfg [' prompt' ]) {
185196 Write-Verbose " Setting based on value in pyvenv.cfg='$ ( $pyvenvCfg [' prompt' ]) '"
0 commit comments