用于 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.