Activate.ps1 cannot be loaded because running scripts is disabled on this system

March 8th 2024 402 views • 1 comments
codie a month ago

[REPOST] I am a noob at Python in Windows. I am getting env\Scripts\Activate.ps1 cannot be loaded because running scripts is disabled on this system. The issue in my Windows machine while activating the virtual environment. Can somebody help me, I am on my Visual Studio CODE.

PS C:\Users\USER\Projects\content_idea_gen> env/Scripts/activate  
env/Scripts/activate : File C:\Users\USER\Projects\content_idea_gen\env\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
+ env/Scripts/activate
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess
pramod a month ago

@codie Here's the solution. It’s the issue from your VSCODE.

  1. Open VSCODE

  2. Press F1, and type Preferences: Open Settings (JSON) and click on it. i.e Simply open settings.json

  3. Go to the bottom of settings.json

  4. Add this line at the end of your visual studio code: "terminal.integrated.shellArgs.windows": ["-ExecutionPolicy", "Bypass"]

  5. Your bottom settings.json should look like this..

….
“explorer.confirmDelete”: false,
“terminal.integrated.shell.windows”: “C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe”,
“terminal.integrated.shellArgs.windows”: [“-ExecutionPolicy”, “Bypass”]
}