Saturday, January 2, 2021

Python: cannot load Activate.ps1 in Visual Studio Code

When running a Python script inside a virtual environment in Visual Studio Code, it shows the following error in the terminal:

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.

One option is to change the ExecutionPolicy. Another option is use set cmd as the default terminal instead of powershell. Personally I prefer the latter.

To change the default terminal:

  1. Ctrl + Shift + P
  2. type: Select Default Shell
  3. select Command Prompt

Ref:
powershell - Visual studio code cmd error: Cannot be loaded because running scripts is disabled on this system - Stack Overflow

No comments: