python virtual environment under Windows Settings

python virtual environment settings under Windows:

virtualenv

    在python开发中,我们可能会遇到一种情况:就是当前的项目依赖的是某一个版本,但是另一个项目依赖的是另一个版本,这样就会造成依赖冲突。在这种情况之下,我们就需要一个工具能够将这两种或几种不同版本的环境隔离开来,需要哪个版本就切换到哪个版本做为默认版本,让每个版本应用都各自拥有一套“独立”的Python运行环境。而virtualenv就可以解决这种情况,它通过创建一个虚拟化的python运行环境,在同一计算机中隔离多个python版本的工具,将我们所需的依赖安装进不同的虚拟环境中,使不同项目之间相互独立、不干扰。也就是说在这个环境中你可以安装私有包,而且不会影响系统中安装的全局Python解释器。

Installation: pip install virtualenv

    如果安装不成功也可以下载virtualenv源码package,通过执行setup.py来安装virtualenv。同时因为python2和python3的不同,因此也有了两种pip和pip3两种python包安装工具,而两种工具安装的virtualenv也是不相同的,python2安装的virtualenv虚拟化出来的python运行环境是python2的,python3安装的virtualenv默认虚拟环境则是python3的。

Instructions

  1. Creation environment: Go to the directory you want to create virtual environments execute the following command;
virtualenv   [环境名] 

This will create a stand-alone Python runtime environment in the current directory, you can use virtualenv --help to see how to use.

  1. Environment
    new Python is placed in the current environment [Environmental name] directory in the directory. With the [Environmental name] The Python environment:
激活虚拟化环境: [环境名]\Scripts\activate

After activating the command line will appear in front of the new environment name, indicates that the current environment is called [the name of the environment] of the Python environment, then install the new environment requires a variety of packages using the command pip. (Pip command comes when you create a new environment)

  1. Exit Virtual Environment
deactivate

At this time he returned to a normal environment, now pip or python are run in the system Python environment.

You can create completely independent of the Python runtime environment for each application, so you can isolate Python environment for each application.

How virtualenv is to create "independent" of the Python runtime environment it? The principle is very simple, is to copy the system to virtualenv Python environment, use the command [Environmental name] \ Scripts \ activate when entering a virtualenv environment, virtualenv will modify environment variables, so the command python and pip point to the current environment virtualenv .

If you want to delete a virtual environment, simply exit the virtual environment, delete the corresponding virtual environment directory. It does not affect other environments.

virtualenvwrapper

virtualenvwrapper tool is based on the Extended Management Pack virtualenv, it will unify all of the virtual environment, for more easily manage the virtual environment, it can do:

将所有虚拟环境整合在一个目录下
管理(新增,删除,复制)虚拟环境
切换虚拟环境

installation

pip install virtualenvwrapper-win

The default virtual environment created is located in C: \ Users \ username \ envs, WORKON_HOME can be customized by environment variables.

通过计算机-->属性-->高级系统设置-->环境变量-->在系统变量中新建“变量名”:WORKON_HOME,变量值:“你自定义的路径”。

Use
all commands can be used: virtualenvwrapper --help to view it;

Create a basic environment:

mkvirtualenv [环境名] 

After you create a successful directory will be created in the earlier WORKON_HOME set specified virtual environment and automatically enter, exit, then also use deactivate. Enter, then again, so do not go looking for the path to virtualenv, you can directly use the command you can enter the virtual environment:

workon  [环境名] 

Frequently used commands are:

删除环境:rmvirtualenv  [环境名] 

列出所有环境:workon 或者 lsvirtualenv -b

python virtual environment under Windows Settings

Guess you like

Origin www.cnblogs.com/zhufanyu/p/12520575.html