Virtualenv : 파이썬 애플리케이션 별 독립실행환경 구성

개요

Virtualenv는 파이썬 어플리케이션들 간의 독립 실행 환경의 생성하는 도구이다. 예를 들어 로컬에서 개발 중인 파이썬 어플리케이션들이 사용하는 라이브러리의 버전이 다를 때 서로 영향을 받지 않도록 환경을 구성할 수 있다. 

설치 및 개발은 다음 순서로 진행한다. 

  1. Virtualenv 설치
  2. virtualenv 적용 디렉토리 설정
  3. virtualenv 적용 디렉토리 활성화
  4. 라이브러리 설치 및 애플리케이션 개발 


Virtualenv 설치

 
C:\Users\username>pip install virtualenv
Collecting virtualenv
C:\Python27\lib\site-packages\pip-8.1.2-py2.7.egg\pip\_vendor\requests\packages\urllib3\util\ssl_.py:318: SNIMissingWarn
ing: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this pla
tform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can u
pgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/s
ecurity.html#snimissingwarning.
  SNIMissingWarning
C:\Python27\lib\site-packages\pip-8.1.2-py2.7.egg\pip\_vendor\requests\packages\urllib3\util\ssl_.py:122: InsecurePlatfo
rmWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may c
ause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information,
see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading virtualenv-15.0.2-py2.py3-none-any.whl (1.8MB)
    100% |################################| 1.8MB 538kB/s
Installing collected packages: virtualenv
Successfully installed virtualenv-15.0.2
C:\Python27\lib\site-packages\pip-8.1.2-py2.7.egg\pip\_vendor\requests\packages\urllib3\util\ssl_.py:122: InsecurePlatfo
rmWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may c
ause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information,
see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
 
C:\Users\username>pip list
django (1.7.11)
mysql-python (1.2.5)
pip (8.1.2)
setuptools (1.1)
virtualenv (15.0.2)
 
C:\Users\username>
 
cs


virtualenv 적용 디렉토리 설정

Virtualenv를 적용할 디렉토리로 이동하여 "virtualenv {디렉토리명}" 명령을 실행한다.

 
c:\virtualenv>virtualenv catnap
New python executable in c:\virtualenv\catnap\Scripts\python.exe
Installing setuptools, pip, wheel...done.
 
c:\virtualenv>
 
cs

virtualenv가 설정된 디렉토리에는 아래 그림과 같은 디렉토리와 파일이 생성된다.



virtualenv 적용 디렉토리 활성화

"activate.bat" 명령어를 실행하면, 경로명 앞에 "(디렉토리명)"이 붙는 것을 확인할 수 있다. 

 
c:\virtualenv\catnap\Scripts>activate.bat
 
(catnap) c:\virtualenv\catnap\Scripts>pip list
pip (8.1.2)
setuptools (23.1.0)
wheel (0.29.0)
 
(catnap) c:\virtualenv\catnap\Scripts>
 
cs


참고. 실행환경

  - OS : Windows 7 Professional K

  - Python : v 2.7.5

  - virtualenv : v 15.0.2



댓글 쓰기

0 댓글