Skip to content

Commit 45217af

Browse files
authored
bpo-38972: Link to instructions to change PowerShell execution policy (GH-19131)
1 parent 7a6f3bc commit 45217af

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

Doc/using/venv-create.inc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ The command, if run with ``-h``, will show the available options::
8383
particular note is that double-clicking ``python.exe`` in File Explorer
8484
will resolve the symlink eagerly and ignore the virtual environment.
8585
86+
.. note::
87+
On Microsoft Windows, it may be required to enable the ``Activate.ps1``
88+
script by setting the execution policy for the user. You can do this by
89+
issuing the following PowerShell command:
90+
91+
PS C:\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
92+
93+
See `About Execution Policies
94+
<ttps:/go.microsoft.com/fwlink/?LinkID=135170>`_
95+
for more information.
96+
8697
The created ``pyvenv.cfg`` file also includes the
8798
``include-system-site-packages`` key, set to ``true`` if ``venv`` is
8899
run with the ``--system-site-packages`` option, ``false`` otherwise.

Lib/venv/scripts/common/Activate.ps1

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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
66
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,
3737
and prefixes the current prompt with the specified string (surrounded in
3838
parentheses) 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
#>
4251
Param(
@@ -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.
166175
if ($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.
180190
if ($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

Comments
 (0)