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
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.
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.
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).
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,
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With