安装:

  1. # Windows 中Python 从3.3 版本开始,自带了一个虚拟环境 venv,不用再单独安装
  2. # Linux
  3. sudo apt-get install python3-venv # 如有不同版本的Python3,可指定具体版本venv:python3.5-venv

使用:

  1. # 创建虚拟环境
  2. python3 -m venv .\myenv # Windows
  3. python3 -m venv myenv # Linux
  4. # 激活环境:
  5. myenv\Scripts\activate.bat # Windows
  6. source myenv/bin/activate # Linux
  7. # 退出:
  8. deactivate
  9. # 安装依赖包:
  10. pip install -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple
  11. # 生成requirements:
  12. pip freeze >requirements.txt