1 virtualenv
1.1 virtualenv安装
pip install virtualenv
1.2 virtualenv基础命令
C:\Users\Lenovo>virtualenv testvir//创建虚拟环境testvir
Using base prefix 'd:\\anaconda3'
New python executable in C:\Users\Lenovo\testvir\Scripts\python.exe
Installing setuptools, pip, wheel...
done.
C:\Users\Lenovo\testvir\Scripts>activate.bat//激活testvir环境
(testvir) C:\Users\Lenovo\testvir\Scripts>
(testvir) C:\Users\Lenovo\testvir\Scripts>deactivate.bat//退出虚拟环境
C:\Users\Lenovo\testvir\Scripts>
2 virtualenvwrapper-win
2.1 virtualenvwrapper-win安装
pip install virtualenvwrapper-win
2.2 virtualenvwrapper-win基本命令
//创建并进入testvir2虚拟环境
C:\Users\Lenovo\testvir\Scripts>mkvirtualenv testvir2
C:\Users\Lenovo\Envs is not a directory, creating
Using base prefix 'd:\\anaconda3'
New python executable in C:\Users\Lenovo\Envs\testvir2\Scripts\python.exe
Installing setuptools, pip, wheel...
done.
//退出虚拟环境
(testvir2) C:\Users\Lenovo\testvir\Scripts>deactivate
//查看虚拟环境
C:\Users\Lenovo\testvir\Scripts>workon
Pass a name to activate one of the following virtualenvs:
==============================================================================
testvir2
//进入testvir2虚拟环境
C:\Users\Lenovo\testvir\Scripts>workon testvir2
(testvir2) C:\Users\Lenovo\testvir\Scripts>
//删除虚拟环境
C:\Users\Lenovo\testvir\Scripts>rmvirtualenv testvir2
Deleted C:\Users\Lenovo\Envs\testvir2
3 tips
将dos窗口关闭后,再次打开dos,想要重新进入虚拟环境需要先cd进入指定目录下 ,比如在我的电脑上,则需要先进入C:\Users\Lenovo\testvir\Scripts
再使用workon进入虚拟环境。
由此发现一个问题,使用workon进入虚拟环境testvir2之后,使用pip安装django,django被安装到了testvir目录下,并没有安装到testvir2环境目录下,暂时的解决方案是只使用virtualenv对虚拟环境进行管理。