Bon Voyage

macOS에 virtualenv 설치하고 사용하기 본문

설치

macOS에 virtualenv 설치하고 사용하기

nangkyeong 2019. 12. 30. 00:09

python 공식 문서는 여기서 확인할 수 있다.

 

12. Virtual Environments and Packages — Python 3.8.1 documentation

12.1. Introduction Python applications will often use packages and modules that don’t come as part of the standard library. Applications will sometimes need a specific version of a library, because the application may require that a particular bug has been

docs.python.org

virtualenv 패키지는 각자의 환경에 설치된 모듈이나 그 버전이 다를 때, 서로 다른 환경에서 같은 application을 실행할 때 발생하는 gap을 해결해 준다. 협업이나 테스트에 유용하게 사용할 수 있다.

# virtualenv 설치 
pip3 install virtualenv

# 실행할 패키지가 있는 해당 directory로 이동 후, 원하는 이름으로 가상환경 생성
virtualenv env_name

# 가상환경 활성화
source env_name/bin/activate

# 활성화된 가상환경 비활성화
deactivate

# 해당 가상 환경에 설치된 패키지 확인
pip list

# 해당 환경에 설치된 패키지 정보를 requirement.txt라는 파일로 저장
pip freeze > requirements.txt

# 해당 환경에 필요한 패키지 정보를 읽어서, 필요한 경우 설치
pip install -r requirements.txt

 

'설치' 카테고리의 다른 글

Using tmux on macOS Catalina  (0) 2019.12.30
macOS Catalina에 python 3, pip 설치하기  (0) 2019.12.30
Windows에서 Node.js 설치하기  (0) 2019.07.17
MacOS에 Jupyter 설치하기  (0) 2019.07.13
MacOS에 Homebrew로 python3 설치하기  (0) 2019.07.13
Comments