I keep getting a PowerShell security error when I try to activate my Python virtual environment or run npm commands inside Visual Studio Code. The terminal shows an execution policy error saying scripts cannot be loaded because running scripts is disabled on this system. It mentions something about PS-Security-Exception and Unauthorised Access. This is really frustrating because I need to work on my projects but VS Code won’t let me run these basic commands. Has anyone else run into this issue? I’m not sure how to fix the PowerShell execution policy without breaking security on my machine.
i had the same issue! try running Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser in an admin PowerShell. that worked for me without causing any security issues.
I switched to Command Prompt instead of PowerShell in VS Code and that fixed it for me. Just open the terminal dropdown and pick cmd over PowerShell. The execution policy thing only hits PowerShell, so your Python virtual env and npm commands work fine in cmd. If you want to stick with PowerShell though, check if your company has group policies blocking your local changes - corporate IT sometimes locks down policy modifications even for individual users.
You don’t need to open a separate PowerShell window - just use VS Code’s integrated terminal. Run Get-ExecutionPolicy to check your current setting, then use Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser. The CurrentUser scope only affects your account, not the whole system. Close and reopen VS Code after making the change. I’ve used this setup for months with zero security issues. RemoteSigned blocks unsigned internet scripts but lets your local scripts run fine.