Reputation: 1
I have a virtual environment named env and a project named project_2. I want to activate the env in VScode but I can't (I can activate that in the command prompt).
When I want to activate a virtual environment in VScode, it shows me this text
PS C:\Users\User1\Documents\programming\python\django> project_2\scripts\activate.ps1
project_2\scripts\activate.ps1 : File
C:\Users\User1\Documents\programming\python\django\project_2\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
+ project_2\scripts\activate.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId: UnauthorizedAccess
What should I do now?
Upvotes: 0
Views: 55
Reputation: 185
You may open the link the error message gives you for example.
You will discover that it's a security related stuff to protect your pc and yourself from unwanted and unauthorized script to run freely on your machine.
Default setting will avoid unsigned (or none at all, I don't remember) script to run.
To override that behavior you can follow what the official documentation says running those Powershell commands to lower the protection and allow scripts execution.
Probably you are looking for the Undefined
or Unrestricted
policy. Also you may need to specify the scope you want that rule to be applied, like:
Set-ExecutionPolicy -ExecutionPolicy Undefined -Scope CurrentUser
Build yourself the command that best fit your needs depending on what policy you want to apply and to which scope.
When you do this you need the PowerShell running as administrator. After you launch that command you need to reboot the VScode editor.
Upvotes: 0