Python 3 内置了用于创建虚拟环境的 venv 模块,Python 2 需要先安装 virtualenv:
pip install virtualenv
创建虚拟环境
1. venv 模块
python3 -m venv flask_env1
2. virtualenv
virtualenv flask_env1
进入虚拟环境
Windows 下:
C:\Users\admin> .\flask_env1\Scripts\activate
Unix 下:
$ source ./flask_env1/Scripts/activate
进入后,终端提示符会显示虚拟环境的名称
(flask_env1) C:\Users\admin>pip list
Package Version
---------- -------
pip 22.0.4
setuptools 58.1.0
wheel 0.37.1
WARNING: You are using pip version 22.0.4; however, version 22.1.1 is available.
You should consider upgrading via the 'C:\Users\admin\flask_env1\Scripts\python.exe -m pip install --upgrade pip' command.
退出虚拟环境
(flask_env1) C:\Users\admin>deactivate
C:\Users\admin>