cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at

Viewed 62614

It was working fine and then i got an error. after solving it i always get this error, whatever the project is

output:

& : File C:\Users\pc\Documents\python\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:3
    + & c:/Users/pc/Documents/python/venv/Scripts/Activate.ps1
    +   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : SecurityError: (:) [], PSSecurityException       
        + FullyQualifiedErrorId : UnauthorizedAccessenter code here
10 Answers

This is because the user your running the script as has a undefined ExecutionPolicy You could fix this by running the following in powershell:

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted

If you are getting error like this,

enter image description here

We can resolve that using the following steps,

  • Get the status of current ExecutionPolicy by the command below:

    Get-ExecutionPolicy
    

    By default it is Restricted. To allow the execution of PowerShell scripts we need to set this ExecutionPolicy either as Unrestricted or Bypass.

  • We can set the policy for Current User as Bypass by using any of the below PowerShell commands:

    Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted -Force
    Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force
    

    Unrestricted policy loads all configuration files and runs all scripts. If you run an unsigned script that was downloaded from the Internet, you are prompted for permission before it runs.

    Whereas in Bypass policy, nothing is blocked and there are no warnings or prompts during script execution. Bypass ExecutionPolicy is more relaxed than Unrestricted.

Might also wanna consider setting it to:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

You'll get a message about Execution Policy change (obviously) to which I said "A" for yes to all. Select what works best for you.

This should allow you to run your own scripts but any originating from anywhere else will require approval.

*above post edited for clarity

Just open Windows Powershell as administrator and execute this command Set-ExecutionPolicy Unrestricted -Force. Issue will be resolved and you can activate it in VS code or CMD.

step 1: -Press the windows-button on your keyboard.
step 2: -Type ‘PowerShell’
step 3: -Right-click Windows PowerShell
step 4: -Click Run as Administrator
step 5: -Run the following command and confirm with ‘Y’
Try this. 

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine

Just type this in the powershell

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted 

and will be enabled

This command work for me:-

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Run This on your PowerShell I think it's work

step 1: -Press the windows-button on your keyboard.

step 2: -Type ‘PowerShell’

step 3: -Right-click Windows PowerShell

step 4: -Click Run as Administrator

step 5: -Run the following command and confirm with ‘Y’ Try this.

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine

workon "namefolder"

.\venv\scripts\activate

I got a similar error about the execution policies. I used the commands posted above. After that, the error message didn't appear.

Run the Powershell as administrator and use those commands.

step 1: -Press the Windows button on your keyboard.
step 2: -Type ‘PowerShell’
step 3: -Right-click Windows PowerShell
step 4: -Click Run as Administrator
step 5: -Run the following command and confirm with ‘Y’ Try this.

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted -Force

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine

enter image description here

Related