virtualenv supports PowerShell, but it may not be available depending on the PowerShell settings. We have summarized the causes and countermeasures.
When using virtualenv activate in PowerShell, you may get the following error:
> virtualenv.exe venv
> .\venv\Scripts\activate
.\venv\Scripts\activate :Script execution is disabled on this system, so file C:\Users\****\developme
nt\venv\Scripts\activate.Unable to read ps1. For more information, see about_Execution_Policies」(http://go.microso
ft.com/fwlink/?LinkID=135170)Please refer to.
Location line:One character:1
+ .\venv\Scripts\activate
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo :Security error: (: ) []、PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
This is due to PowerShell's script execution policy. You can check the current execution policy with the Get-ExecutionPolicy
command.
> Get-ExecutionPolicy
Restricted
Restricted
means "No script can be executed. Windows PowerShell can only be used in interactive mode."
For more information on execution policies, see the official Microsoft documentation (https://technet.microsoft.com/en-us/library/ee176847.aspx).
If it remains Restricted
, it cannot be activated. There are the following methods as countermeasures.
Launch PowerShell with administrator privileges and use the Set-ExecutionPolicy
command to change the execution policy to RemoteSigned
. RemoteSigned
means" The downloaded script can only be executed if it is signed by a trusted publisher. "
> Set-ExecutionPolicy RemoteSigned
The dialog "Do you want to change the execution policy?" Appears. Enter "Y" and press Enter to proceed.
In addition, official document of virtualenv says that Set-ExecutionPolicy AllSigned
is fine, but [^ #] my In the environment, I got the following error and could not activate.
[^ #]: It says "In order to use the script, you can relax your system's execution policy to AllSigned, meaning all scripts on the system must be digitally signed to be executed. Since the virtualenv activation script is signed by one of the authors (Jannis Leidel) this level of the execution policy suffices. "
.\venv\Scripts\activate :File C:\Users\****\development\venv\Scripts\activate.Unable to read ps1. File
C:\Users\****\development\venv\Scripts\activate.ps1 is not digitally signed. This script is on the current system
Cannot be executed. For more information on script execution and setting execution policies, see about_Execution_Policies」(http://go.micr
osoft.com/fwlink/?LinkID=135170)Please refer to.
Location line:One character:1
+ .\venv\Scripts\activate
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo :Security error: (: ) []、PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
If you don't want to change the settings just for virtualenv, it is recommended to add the -Scope Process
option to the command of Countermeasure 1 and set" Change execution policy only for the currently open PowerShell window ". In this case PowerShell does not need administrator privileges.
> Set-ExecutionPolicy RemoteSigned -Scope Process
If you don't want the dialog to appear every time, you can omit it with the -force
option.
If you activate after implementing the above measures, the error will not occur. You should see the virtualenv directory name on the left side of the screen as shown below.
Recommended Posts