Due to company constraints I cannot immediately execute PowerShell commands:
File C:...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
The workaround I already found (thanks Stack!) is to execute, in the command line (not as a PS script):
Set-ExecutionPolicy Unrestricted -Scope Process
This solves the problem and when I'm running code for real, it works well. When I am in the middle of a development/debugging session in VS Code, however, this command does not execute.
Is there a place in one of the JSON setup files where I can pre-execute the above command before PS or cmd or the python debugger attempts to run Activate.ps1? This fixes venv problems for me and anyone else with problematic corporate script execution policies.
VS Code supports adding
tasks.jsonfiles to set up automatic tasks.A simple example:
This setting is to run the
dircommand to read the files in the directory when opening the folder.How to create a
task.jsonfile?Open command palette with Ctrl+Shift+P
Search and select Tasks:Configure Task
Choose Create task.json file fromtemplate
Choose Others
More about
tasks.json: Click herePS:
Regarding debugging, the
launch.jsonfile can also help a lot. Click here and here to know more.