Python에서 가상 환경이란,
Python interpreter, packages, 그리고 pip와 같은 tool들을 포함하고 있는 폴더이다.
공식 문서에는 이렇게 적혀있다.
A virtual environment is (amongst other things):
Used to contain a specific Python interpreter and software libraries and binaries which are needed to support a project (library or application). These are by default isolated from software in other virtual environments and Python interpreters and libraries installed in the operating system.
즉, 가상환경은 프로젝트에 필요한 python interpreter, software library등을 포함하는데 이러한 interpreter, library들을 운영 체제나, 다른 환경에서의 software와 독립적으로 실행되도록 한다.
Python installs와 관련된 pip packages들을 분리시키는 것을 돕고, 사용자들이 다른 프로젝트나 다른 시스템에서 사용되는 것들과 독립적인 프로젝트 자신의 package들을 관리하고 설치하도록 한다.
그렇다면 가상 환경을 항상 사용해야할까?
항상 사용해야한다!
물론 예외도 있다. Python Standard Library만을 사용한 program의 경우 (pip install로 설치하는 module이 없는 경우), 가상환경을 고려할 필요는 없다.
하지만 아주 간단한 프로그램을 제외하고는 가상환경을 사용하여 프로그래밍을 하여야 한다.
가상환경은 안정적이고 재현될 수 있고 이동성이 좋은 환경(stable, reproducible, and portable environment) 이고 가상환경을 통해 패키지 버전과 업데이트를 control 할 수 있기 때문이다.
<가상 환경 설치 및 실행>
// 가상환경 설치
python -m venv '가상환경이름'
// 가상환경 실행
source '가상환경이름'/bin/activate
// 가상환경 비활성화
deactivate
<참고>
A Complete Guide to Python Virtual Environments (2022) – Dataquest
As you get started in Python, you may be wondering: What are Python virtual environments? Why should I use them? How do I use them? With examples, this tutorial answers these questions and more!
www.dataquest.io
Python and Virtual Environments | Department of Computer Science Computing Guide
Navigate to the Download Python page, navigate to the version of your choice, download the corresponding “XZ compressed source tarball,” and put it in a temporary directory in your project space. For example (assuming your project space is at /n/fs/myp
csguide.cs.princeton.edu
https://docs.python.org/3/library/venv.html
venv — Creation of virtual environments
Source code: Lib/venv/ The venv module supports creating lightweight “virtual environments”, each with their own independent set of Python packages installed in their site directories. A virtual en...
docs.python.org
'Django' 카테고리의 다른 글
| [Python] OpenAPI JSON 데이터 받아오기 (1) | 2024.01.18 |
|---|---|
| [Python] package 목록 관리 (requirements.txt) (6) | 2023.10.05 |
| [Django] DRF JWT 인증 방식을 이용한 회원가입 & 로그인 (3. 이메일 로그인/로그아웃) (4) | 2023.09.01 |
| [Django] DRF JWT 인증 방식을 이용한 회원가입 & 로그인 (2. 이메일 회원가입) (3) | 2023.08.18 |
| [Django] DRF JWT 인증 방식을 이용한 회원가입 & 로그인 (1. User Custom) (3) | 2023.08.18 |