Windows
- 创建虚拟环境
mkdir <虚拟环境目录>
virtualenv –p <解释器路径> –-no-site-packages <虚拟环境目录>
- 启动虚拟环境
运行<虚拟环境目录>/script/activate
- 退出虚拟环境
运行<虚拟环境目录>/script/deactivate
- 删除虚拟环境
直接删除虚拟环境所在的目录就可以了
Linux
-
创建虚拟环境
mkdir <虚拟环境目录>
$ virtualenv -p <解释器路径> –-no-site-packages <虚拟环境目录>
-
启动虚拟环境
$ source <虚拟环境目录>/bin/activate
-
退出虚拟环境
$ deactivate
-
删除虚拟环境
$ rm –r <虚拟环境目录>
注:目前(20.0.0+),已经取消了–-no-site-packages参数,默认直接使用–-no-site-packages模式
requirements
virtualenv虚拟环境配合pip的freeze功能,可以一次性快捷的将整个环境下的第三方模块全部记录下来:
pip freeze > d:
equirements.txt
对应的,也可以用它一次性通过在别的机器上或虚拟环境里,将文件里列出的第三方库安装起来。只需要使用命令:
pip install -r requirements.txt