3

I am using Windows PowerShell. But, I don't know why, when I try to activate a python virtual environment, I get this error:

venv\Scripts\activate : File C:\Users\Dell\Desktop\flask\microblog\venv\Scripts\Activate.ps1 
cannot be loaded because running scripts is disabled on this system. For more information, see    
about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ venv\Scripts\activate
+ ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

This is the command I ran:

venv\Scripts\activate

This is the first time it has happened. What is the problem?

mklement0
  • 382,024
  • 64
  • 607
  • 775
Samyak Jain
  • 347
  • 1
  • 4
  • 17
  • In PowerShell on Windows, script execution is disabled by default. Enable it with [`Set-ExecutionPolicy`](https://docs.microsoft.com/powershell/module/microsoft.powershell.security/set-executionpolicy). There are 3 scopes; more specific ones have higher precedence: `-Scope LocalMachine` (requires admin rights), `-Scope CurrentUser`, or `-Scope Process` (current process only). The PowerShell CLI accepts a process-specific `-ExecutionPolicy ` too . Execution policies can also be set via GPO, in which case they cannot be changed or overridden with `Set-ExecutionPolicy` or via the CLI. – mklement0 Nov 18 '20 at 15:53

1 Answers1

5

Looks like running powershell scripts is disabled on your machine. you can run as admin:

Set-ExecutionPolicy RemoteSigned

or

Set-ExecutionPolicy Unrestricted

this should solve the problem

lww
  • 624
  • 1
  • 7
  • 14
  • 1
    That works, but you don't necessarily need admin privileges, namely if you use `-Scope CurrentUser`. Conversely, if the execution policy is set via GPO (Group Policy Objects), it can't be changed with `Set-ExecutionPolicy`. – mklement0 Nov 18 '20 at 15:55