이 시스템에서 스크립트를 실행할 수 없으므로 ...ps1 파일을 로드할 수 없습니다.
Python 가상환경 오류 - 실행 정책 편집
2024.12.18 - [프로그램 설치] - 파이썬(python) 설치하기
파이썬(python) 설치하기
파이썬 다운로드 Download Python | Python.org Download PythonThe official home of the Python Programming Languagewww.python.org3.8~3.12각 버전 별 다운로드 페이지(가장 마지막 배포 버전 기준) 3.8(지원 종료됨) Python Releas
violetookamiscythe.tistory.com
2024.12.19 - [프로그램 설치] - Visual Studio Code (vscode) 설치
Visual Studio Code (vscode) 설치
Visual Studio Code - Code Editing. Redefined Visual Studio Code - Code Editing. RedefinedVisual Studio Code redefines AI-powered coding with GitHub Copilot for building and debugging modern web and cloud applications. Visual Studio Code is free and avail
violetookamiscythe.tistory.com
2024.12.22 - [Python] - Python 가상환경(venv) 생성 및 실행 - VSCode
Python 가상환경(venv) 생성 및 실행 - VSCode
2024.12.18 - [프로그램 설치] - 파이썬(python) 설치하기 파이썬(python) 설치하기파이썬 다운로드 Download Python | Python.org Download PythonThe official home of the Python Programming Languagewww.python.org3.8~3.12각 버전 별
violetookamiscythe.tistory.com
파이썬 가상환경 실행 시 생기는 실행 정책 오류에 대한 해결법입니다.
요약
1.
시작 버튼을 우클릭 후 Windows Powershell(관리자)를 실행한다.
2.
나타난 Powershell에 다음 명령어를 입력한다.
Get-ExecutionPolicy
3. 결과가 Restricted로 표기된다면 다음 명령어를 Powershell에 입력한다.
Set-ExecutionPolicy RemoteSigned
4. 실행 규칙을 변경할지 물어보면 예(Y)를 누르고 엔터를 입력한다.
5. 다시 Powershell에 명령어를 입력한다.
Get-ExecutionPolicy
6. 결과가 RemoteSigned로 표기된다면 가상환경을 실행해본다.
주로 컴퓨터를 포맷하고 다시 설치했을 때, 파이썬을 설치하고 가상환경을 실행해 보면 다음 오류가 뜨면서 가상환경이 실행되지 않는 경우가 있습니다.

실행 정책 관련 문제입니다.
컴퓨터 입장에서
가상환경 스크립트가 남이 작성한 스크립트이고,
그래서 악성코드인지 정상코드인지 모르겠으니,
일단 실행하지 않겠다.
라고 설명한다고 보면 되겠습니다.
ps1 파일은 Windows의 PowerShell 스크립트 파일입니다.
PowerShell 실행 정책을 바꿔봅시다.
시작 버튼을 우클릭 하여 중간에 있는 Windows PowerShell(관리자) 버튼을 눌러줍시다.
사용자 계정 컨트롤에서 이 앱이 컴퓨터를 변경할 수 있도록 허용할지 물으면 예를 눌러 권한을 승인해줍니다.

PowerShell이 관리자 권한으로 실행되면 다음 명령어를 입력해 줍시다.
Get-ExecutionPolicy
※Get-Ex 정도만 치고 tab 키를 누르면 나머지가 자동완성 됩니다.
가상환경이 실행되지 않는 상태라면 Restricted로 나타날 것입니다.

Restricted 문구를 확인했다면 이제 실행 정책을 바꿔봅시다.
PowerShell에 다음 명령어를 입력해주세요.
Set-ExecutionPolicy RemoteSigned
※ 역시 tab 키를 통해 자동완성이 가능합니다. Set-ex, remo 정도만 작성하고 각각 탭 키를 눌러보세요.
RemoteSigned 말고 여러가지 다른 정책이 있습니다.
좀 더 알고싶으신 분들은 아래 접은 글에서 확인해보세요.(영문)
Set-ExecutionPolicy (Microsoft.PowerShell.Security) - PowerShell | Microsoft Learn
Set-ExecutionPolicy (Microsoft.PowerShell.Security) - PowerShell
The Set-ExecutionPolicy cmdlet changes PowerShell execution policies for Windows computers. For more information, see about_Execution_Policies. Beginning in PowerShell 6.0 for non-Windows computers, the default execution policy is Unrestricted and can't be
learn.microsoft.com
-ExecutionPolicy
Specifies the execution policy. If there are no Group Policies and each scope's execution policy is set to , then becomes the effective policy for all users.UndefinedRestricted
The acceptable execution policy values are as follows:
- AllSigned. Requires that all scripts and configuration files are signed by a trusted publisher, including scripts written on the local computer.
- Bypass. Nothing is blocked and there are no warnings or prompts.
- Default. Sets the default execution policy. for Windows clients or for Windows servers.RestrictedRemoteSigned
- RemoteSigned. Requires that all scripts and configuration files downloaded from the Internet are signed by a trusted publisher. The default execution policy for Windows server computers.
- Restricted. Doesn't load configuration files or run scripts. The default execution policy for Windows client computers.
- Undefined. No execution policy is set for the scope. Removes an assigned execution policy from a scope that is not set by a Group Policy. If the execution policy in all scopes is , the effective execution policy is .UndefinedRestricted
- Unrestricted. Beginning in PowerShell 6.0, this is the default execution policy for non-Windows computers and can't be changed. Loads all configuration files and runs all scripts. If you run an unsigned script that was downloaded from the internet, you're prompted for permission before it runs.
실행 규칙을 변경할지 물어보면 Y를 누르고 엔터 키를 입력해 변경합니다.

변경이 잘 되었다는 별도의 안내가 없으니, 변경되었는지 직접 확인해 봅시다.
다시 PowerShell에 Get-ExecutionPolicy를 입력해주세요.
Get-ExecutionPolicy

RemoteSigned로 변경이 잘 된것을 확인할 수 있습니다.
이제 VSCode로 가서 가상환경을 실행해 봅시다.

잘 동작하는 것을 확인할 수 있습니다.
'Python > 가상환경' 카테고리의 다른 글
설치된 다른 버전으로 파이썬 가상환경 생성하기 (0) | 2025.01.09 |
---|---|
Python 가상환경(venv) 생성 및 실행 - VSCode (0) | 2024.12.22 |
Python 가상환경(venv) 생성 및 실행 - cmd (0) | 2024.12.21 |