• Home
  • About
    • lahuman photo

      lahuman

      열심히 사는 아저씨

    • Learn More
    • Facebook
    • LinkedIn
    • Github
  • Posts
    • All Posts
    • All Tags
  • Projects

Python에서 virualenv 과 virtualenvwrapper 설치하기

24 Nov 2017

Reading time ~1 minute

virualenv 와 virtualenvwrapper

virualenv

여러개의 Python 프로젝트를 진행할때 의존성 문제를 해결 하기 위하여 가상환경을 구성하는 모듈 이다.

virtualenvwrapper

virualenv 를 감싸서 쉽게 관리 하기 위한 모듈이다.

설치

pip install virtualenv virtualenvwrapper

virtualenvwrapper 설정

~/.bash_profile 에 설정

# Create a backup of your .bash_profile
cp ~/.bash_profile ~/.bash_profile-org

# Be careful with this command
printf '\n%s\n%s\n%s' '# virtualenv' 'export WORKON_HOME=~/virtualenvs' \
'source /usr/local/bin/virtualenvwrapper.sh' >> ~/.bash_profile

virtual 환경 사용

source ~/.bash_profile

mkdir -p $WORKON_HOME

mkvirtualenv api

# Exit the 'api' virtual environment
deactivate

virtualenv 사용 팁

구성된 가상 환경 실행 방법

workon api

가상환경 종료 방법

deactivate

가상 환경에 설치된 모듈 정보 저장

우서 requests 모듈을 설치 한다.

pip install requests

가상 환경에 필요한 모듈을 모두 설치 한 이후, 다음 명령으로 환경에 대한 정보를 저장한다.

pip freeze > requirements.txt

다른 곳에서 해당 환경에 대한 설치는 다음과 같다.

pip install -r requirements.txt

참고 자료

Install virtualenv and virtualenvwrapper on Mac OS X Pipenv & Virtual Environments



python Share Tweet +1