用於 windows 的 virtualenvwrapper 的虛擬環境

假設你需要處理三個不同的專案專案 A,專案 B 和專案 C.專案 A 和專案 B 需要 python 3 和一些必需的庫。但是對於專案 C,你需要 python 2.7 和依賴庫。

因此,最佳做法是將這些專案環境分開。要建立單獨的 python 虛擬環境,需要按照以下步驟操作:

步驟 1: 使用以下命令安裝 pip:python -m pip install -U pip

第 2 步: 然後使用命令安裝“virtualenvwrapper-win”包(命令可以執行 windows power shell):

pip install virtualenvwrapper-win

第 3 步: 使用命令:mkvirtualenv python_3.5 建立一個新的 virtualenv 環境

第 4 步: 使用命令啟用環境:

workon < environment name>

virtualenvwrapper 的主要命令:

mkvirtualenv <name>
Create a new virtualenv environment named <name>. The environment will be created in WORKON_HOME.

lsvirtualenv
List all of the enviornments stored in WORKON_HOME.

rmvirtualenv <name>
Remove the environment <name>. Uses folder_delete.bat.

workon [<name>]
If <name> is specified, activate the environment named <name> (change the working virtualenv to <name>). If a project directory has been defined, we will change into it. If no argument is specified, list the available environments. One can pass additional option -c after virtualenv name to cd to virtualenv directory if no projectdir is set.

deactivate
Deactivate the working virtualenv and switch back to the default system Python.

add2virtualenv <full or relative path>
If a virtualenv environment is active, appends <path> to virtualenv_path_extensions.pth inside the environment’s site-packages, which effectively adds <path> to the environment’s PYTHONPATH. If a virtualenv environment is not active, appends <path> to virtualenv_path_extensions.pth inside the default Python’s site-packages. If <path> doesn’t exist, it will be created.