about 4 years ago

安裝

使用 pip 進行安裝

$ pip install virtualenv
$ pip install virtualenvwrapper

設定 .bashrc

參考 virtualenvwrapper 檔案 (/usr/local/bin/virtualenvwrapper.sh)

# Setup:
#
#  1. Create a directory to hold the virtual environments.
#     (mkdir $HOME/.virtualenvs).
#  2. Add a line like "export WORKON_HOME=$HOME/.virtualenvs"
#     to your .bashrc.
#  3. Add a line like "source /path/to/this/file/virtualenvwrapper.sh"
#     to your .bashrc.
#  4. Run: source ~/.bashrc
#  5. Run: workon
#  6. A list of environments, empty, is printed.
#  7. Run: mkvirtualenv temp
#  8. Run: workon
#  9. This time, the "temp" environment is included.
# 10. Run: workon temp
# 11. The virtual environment is activated.

列出相關 command

  1. 建立 virtual 環境
    $ mkvirtualenv YOUR_ENV_NAME
    
  2. 列出 virtual 環境

    $ workon
    # 有安裝 wrapper
    $ lsvirtualenv
    
  3. 進入 virtual 環境

    $ workon [YOUR_ENV_NAME]
    
  4. 退出 virtual 環境

    $ deactivate
    

Reference

Virtual Environments
virtualenvwrapper command reference
Python 的虛擬環境及多版本開發利器─Virtualenv 與 Pythonbrew

← 使用 gmail 來讀 RSS 資料 深入淺出 Python 閱讀記錄 →