“Running scripts is disabled on this system” in PowerShell: fixing venv activate and npm
PowerShell has an <i>execution policy</i> that decides which <code>.ps1</code> script files may run. On Windows desktops it starts as <code>Restricted</code>: commands typed by hand work, but no script file runs. Activating a Python virtual environment and the npm, npx and yarn shims are all script files, so they hit it first.
The messages you might see
.venv\Scripts\Activate.ps1 : File C:\code\app\.venv\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.
npm : File C:\Program Files\nodejs\npm.ps1 cannot be loaded because running scripts
is disabled on this system.
+ FullyQualifiedErrorId : UnauthorizedAccess
Check what’s set
Get-ExecutionPolicy -List
This lists each scope from strongest to weakest: MachinePolicy and UserPolicy (set by Group Policy), then Process, CurrentUser and LocalMachine. The first one that isn’t Undefined wins.
The policies in plain words
| Policy | What runs |
|---|---|
Restricted | No script files at all (Windows desktop default) |
AllSigned | Only scripts signed by a publisher you trust |
RemoteSigned | Your own local scripts; downloaded ones must be signed (Windows Server default, and the usual developer choice) |
Unrestricted | Everything, with a warning for downloaded scripts |
Bypass | Everything, no warnings; meant for one process or automation |
Fixes, from smallest to biggest
| Option | Command |
|---|---|
| Don’t run a script at all: call the venv’s Python directly | .venv\Scripts\python.exe -m pip install -r requirements.txt |
| Use the Command Prompt versions | .venv\Scripts\activate.bat, or npm.cmd install (the .cmd shims ignore the policy) |
| Allow scripts in this window only | Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass |
| Allow your own scripts permanently, for your account | Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned |
| A downloaded script is still blocked under RemoteSigned | Read it first, then Unblock-File .\setup.ps1 to remove the downloaded-from-the-internet mark |
When it won’t change
If Set-ExecutionPolicy warns that a policy set at a more specific scope overrides it, or Get-ExecutionPolicy -List shows a value under MachinePolicy or UserPolicy, your organisation sets it through Group Policy. Your change is ignored. Use the no-script options above (the venv’s python.exe, activate.bat, npm.cmd) or ask IT, rather than trying to get around it.
Is this a security setting?
Only loosely. Microsoft describes the execution policy as a safety feature that stops scripts running by accident, not a security boundary: anyone can paste a script’s contents into the prompt. RemoteSigned for your own account keeps the useful part (a warning wall for downloaded scripts) without getting in the way of everyday tools.
Related
Venv working but Python still can’t find a package? See ModuleNotFoundError: No module named. pip complaining about an externally managed environment on Linux is the reason to use a venv in the first place. Moving the same script to Linux or macOS? See ./script.sh: Permission denied. Activate.ps1 runs but which python / Get-Command python is still wrong? See Python venv not activating. Also: && is not a valid statement separator · curl is Invoke-WebRequest · The term node is not recognized.
Questions
How do I fix running scripts is disabled on this system?
Run Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned in PowerShell, confirm, and open a new terminal. It needs no administrator rights.
How do I activate a Python venv without changing the execution policy?
Use .venv\Scripts\activate.bat from Command Prompt, or skip activation and call .venv\Scripts\python.exe directly.
Why does npm say npm.ps1 cannot be loaded?
PowerShell prefers the npm.ps1 shim, which is a script file blocked by the execution policy. Change the policy for your user, or run npm.cmd instead.
What if Set-ExecutionPolicy doesn't change anything?
A Group Policy value under MachinePolicy or UserPolicy overrides it. Use the .cmd or python.exe alternatives, or ask whoever manages the machine.
Published .