:bulb: This post explains how to fix the permission error you get when running commands in the Visual Studio Code Terminal (PowerShell).

[01] The Error

  • “Cannot be loaded because running scripts is disabled on this system…”
  • Security error, PSSecurityException
  • FullyQualifiedErrorID, UnauthorizedAccess
1
2
3
4
PS D:\Code\Python> .\.venv-doit-django\Scripts\activate
.\.venv-doit-django\Scripts\activate : 이 시스템에서 스크립트를 실행할 수 없으므로 ...
    + CategoryInfo          : 보안 오류: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

2022-12-30 16 36 45

[02] Cause and Solution

  • PowerShell is configured by default to disallow running script files.
  • Possible values
Value Description
Restricted default, scripts cannot be run
AllSigned only signed (trusted) scripts run
RemoteSigned locally created scripts and signed scripts run
Unrestricted all scripts can run
ByPass all scripts run with no warning or block
Undefined no policy set

2-1. On Windows 10

Search bar → PowerShell → Run as Administrator → Change script execution policy

2022-12-30 16 38 34

1
2
3
4
5
# Check the current policy
get-ExecutionPolicy

# Set the policy (RemoteSigned)
Set-ExecutionPolicy RemoteSigned

2022-12-30 16 40 26

[03] Verifying After the Change

  • You can confirm that the script file (here, a Python virtual environment) now runs correctly.

2022-12-30 16 44 13