2013년 7월 22일 월요일

VirtualEnv 설치

VirtualEnv 설치

  1. VirtualEnv를 사용하는 이유
홈페이지에서 발췌
virtualenv is a tool to create isolated Python environments.
The basic problem being addressed is one of dependencies and versions, and indirectly permissions. Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both these applications? If you install everything into /usr/lib/python2.7/site-packages (or whatever your platform's standard location is), it's easy to end up in a situation where you unintentionally upgrade an application that shouldn't be upgraded ……(후략)……

홈페이지는 아래와 같다.



  1. 프로그램 설치
아래 링크에서 파일을 다운로드 받아 압축을 해제 한다.
$ sudo apt-get install python-setuptools
$ sudo easy_install pip
$ sudo pip install virtualenv

  1. 설정

위 명령으로 virtualenv를 깔고 나면 virtualenv 명령어를 바로 쓸 수 있다.
$ mkdir ~/work/py-envs
$ cd ~/work/py-envs
$ virtualenv --no-site-packages --distribute <환경이름>

--no-site-packages 옵션은 파이썬 기본 실행환경에 있는 라이브러리를 쓰지 않겠다는 의미이며, --distribute 옵션은 setuptools 대신에 distribute를 쓰겠다는 뜻이다
Figure 1 새로운 가상환경 생성
적용은 아래와 같이 실행하면, 가상환경을 사용할 수 있다.
$ source <환경이름>/bin/activate


Figure 2 가상환경 사용



  1. Appendix
A) Python 버전 별로 설치하기
파이썬을 버전별로 설치하기 위해서는 소스를 직접 컴파일하고, 설치 디렉토리를 설정하여준다.
소스는 아래 사이트에서 다운로드 할 수 있다.

소스 컴파일은 압축 해제 후, 아래와 같이 실행하면 설정된 디렉토리에 설치가 완료된다.
$ configure --prefix=<설치디렉토리>
$ make
$ sudo make install

B) 버전 별로 설치된 python과 같이 사용하기
virtualenv와 같이 사용하는 경우는 아래와 같이 파이썬 설치 후, 실행파일을 옵션으로 지정해주면 된다.
virtualenv -p <파이썬 실행파일>
ex) virtualenv -p /usr/bin/python2.6

댓글 없음:

댓글 쓰기