Installation python2 and python3 virtual environment on windows

First, install the windows

1. Install python

Were installed Python2 and Python3

python3.7 default installation directory

C:\Users\Administrator\AppData\Local\Programs\Python\Python37

Installation directory python.exe, pip.py Custom whether to amend

2. Installation and virtualenvwrapper-win virtualenv

pip2 install virtualenv2 -i https://pypi.douban.com/simple
pip3 install virtualenv3 -i https://pypi.douban.com/simple
pip2 install virtualenvwrapper-win -i https://pypi.douban.com/simple
pip3 install virtualenvwrapper-win -i https://pypi.douban.com/simple

 3. Modify the virtual environment

 

------- distinguish between different environments py2 py3 and placed into different workspaces workon folder -----------

 

Python2 and modify the virtual environment script name in the 3 \ scripts were changed to:

(1) virtualenv2 and virtualenv3

 

(2) mkvirtualenv2 and mkvirtualenv3

note:

34 rows need to change virtualenv2, in order to create not only when the directory is changing, but the use of an interpreter python2

34 rows need to change virtualenv3, in order to create not only when the directory is changing, but the use of an interpreter python3

(3) rmvirtualenv2, rmvirtualenv3

(4)workon2,workon3

Copy the folder are files workon Py2, and the scripts py3 file workon2, workon3, copy the file to open, following replacement WORKON_HOME

(5)workon

Add workon while viewing path workon2 and workon3 virtual environments

4. Modify the HOME environment variable

File folder environment variable can be newly created empty folder

#py2放在Envs2文件夹下,py3放在Envs3文件夹下
变量名:WORKON2_HOME
变量路径:以后的py2虚拟环境都创建在这里
变量名:WORKON3_HOME
变量路径:以后的py3虚拟环境都创建在这里

New Envs, Envs2, Envs3 folder

-------- does not distinguish between workon2 and workon3, various virtual environments put under the same folder ---------

#py2和py3放在Envs文件夹下
变量名:WORKON_HOME
变量路径:以后的虚拟环境都创建在这里

 

 5. Use

 

And workon3 ------------ --------- differentiate workon2

 

(1) Create: 

A. fixed position

Creating an environment in D: // envs2, under envs3

mkvirtualenv2/3    #创建不同的Python虚拟环境

Creating an environment in C: \ Users \ Administrator \ Envs under (condition: Create C: \ Users \ Administrator \ Envs directory)

mkvirtualenv

B. arbitrary position

注意:删除和切换操作就用不了,因为没有对该虚拟环境设置环境变量(不建议使用)

virtualenv2/3

(2)切换:   

workon2/3    #进行环境切换,同一个目录下WORKON显示不用切换

(3)删除:   

 rmvirtualenv2/3    #删除环境

(4)退出:

 deactivate    #退出环境

(5)其他命令

并未做区分py2py3的测试 

workon name-of-venv # 进入虚拟环境
deactive # 退出虚拟环境
lsvirtualenv # 列出可用的虚拟环境
mkvirtualenv name-of-venv # 创建虚拟环境 rmvitualenv name-of-venv # 删除虚拟环境 cdvirtualenv name-of-venv # 进入虚拟环境目录 cdsitepackages name-of-venv # 进入虚拟环境的site-packages目录 lssitepackages name-of-venv # 列出site-packages目录的所有软件包

 

---------不区分workon2和workon3------------

 

mkvirtualenv  -p  C:\Python36\python.exe env3    # 创建python3虚拟环境

mkvirtualenv  -p  C:\Python27\python.exe env2    # 创建python2虚拟环境

Guess you like

Origin www.cnblogs.com/benjamin77/p/11529088.html