Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 737
Ahmed Adel Avatar asked Apr 18 '21 15:04

Ahmed Adel


People also ask

How do you fix Cannot be loaded because running scripts is disabled on this system?

Here is how: Open PowerShell Console by selecting “Run as Administrator” and get the execution Policy with the command: Get-ExecutionPolicy to get the current policy applied, such as “Restricted”. Set the execution Policy with the following command: Set-ExecutionPolicy RemoteSigned. Type “Y” when prompted to proceed.

Why is running scripts disabled on this system?

While running PowerShell script, if you get running scripts is disabled on this system, it is because the PowerShell execution policy is set up by default as Restricted and doesn't allow to run script. PowerShell has built-in security features implemented.

How do I enable scripts in Windows 10?

Open Start. Search for PowerShell, right-click the top result, and select the Run as administrator option. Type the following command to allow scripts to run and press Enter: Set-ExecutionPolicy RemoteSigned. Type A and press Enter (if applicable).


Video Answer


4 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
like image 71
mcdonalds291 Avatar answered Oct 24 '22 00:10

mcdonalds291


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.

like image 36
Codemaker Avatar answered Oct 23 '22 23:10

Codemaker


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

like image 11
L. Nader Avatar answered Oct 23 '22 22:10

L. Nader


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.

like image 5
Abdul Qayyum Avatar answered Oct 23 '22 23:10

Abdul Qayyum