The use of environmental management pipenv

installation

pip3 install pipenv   

Configuration

配置 环境变量 WORKON_HOME  , 表示 生成的虚拟环境 文件 的 存放位置

Create a virtual environment

  • method one
pipenv  --python  3.7     // 创建 虚拟 环境, 指定 宿主 python 环境 版本

After creating a successful, this virtual environment automatically generates configuration files in the current working directory Pipfile run this command

Pipfile :

  1 [[source]]
  2 name = "pypi" 
  3 url = "https://pypi.org/simple"  //  指定 pip  源
  4 verify_ssl = true
  5 
  6 [dev-packages]                  // 
  7 
  8 [packages]                      // 记录 此环境 所安装的 第三方 包
  9
 10 
 11 [requires]
 12 python_version = "3.7"         // 当前环境的 版本
  • Second way
pipenv shell    // 进入当前目录下的 Pipfile 文件对应的虚拟环境, 若当前目录不存在, 则先创建环境, 再进入
  • Three ways
pipenv install [xxxxx]  // 向当前所在虚拟环境安装第三方包, 若未存在于虚拟环境, 则先创建环境, 再安装, 
                          也将生成此虚拟环境的 元 信息文件 Pipfile.lock
  • Four ways
pipenv lock   //  生成当前所在虚拟环境的 元 信息文件 Pipfile.lock,若未存在于虚拟环境,则先创建环境, 再生成

Explanation

虚拟环境存在的标志: 当前目录下是否存在 虚拟环境配置文件 Pipfile ,
以上创建环境 二 、三、 四 方式, 会先判断当前目录是否存在  Pipfile 文件,,若不存在, 则先创建, 故也可用于 创建虚拟环境。
Pipfile 包含关于项目的依赖包的信息,并取代通常在Python项目中使用的 requirements.txt 文件
每安装 一个包 , 都会 在 Pipfile  和 Pipfile.lock 中 记录此包的相关信息

Replace the pip source

打开pipfile文件,修改url属性
,,随意选。
url = "https://pypi.douban.com/simple"             // douban源
url = "https://pypi.tuna.tsinghua.edu.cn/simple"   // 清华源
url = "https://mirrors.aliyun.com/pypi/simple"     // 阿里云源

Other commands

pipenv  install xxxx==2.3.1  // 安装  pip  包
pipenv uninstall xxxx        // 卸载  pip  包
pipenv  shell                // 进入 环境 , 原理 为: 改变 操作系统 的 PATH  环境变量
exit                         // 退出 环境
pipenv lock                  // 生成 环境 元信息 文件 Pipfile.lock
pipenv uninstall --all       // 卸载全部包, 也可指定 , 并将其从Pipfile中删除
pipenv sync                  // 安装Pipfile.lock中指定的所有包 (完整移植开发环境)
pipenv run                   // 在未激活虚拟环境时可以直接使用虚拟环境的Python执行命令
pipenv run pip freeze        // 
pipenv install -r requirements.txt   
pipenv clear                // 卸载 Pipfile.lock 中未指定的所有包
pipenv --three  // 创建python3环境
pipenv --two    // 创建python2环境
pipenv --where  // 显示目录信息
pipenv --venv   // 显示虚拟环境信息
pipenv --envs   // 输出环境变量信息
pipenv --py     // 显示Python解释器信息
pipenv –pypi-mirror  xxx  // 指定PyPi的镜像
pipenv –site-packages     // 为虚拟环境启用site-packages
pipenv graph    // 查看目前安装的库及其依赖
pipenv check    // 检查安全漏洞

to sum up:

The traditional migration environment or use the virtualenvtool, should help requirements.txtfile, of course, can be another name.

Which records the version information for all packages in the current environment, command pip freeze --all > requirements.txtand pip install -r requirements.txt.

The use of pipenv tool, based on environment configuration file is automatically created Pipfileand meta-information file Pipfile.lock, the file can be freely according to migration environment, commandpipenv install

Reference links

Github

Advanced Usage

Guess you like

Origin www.cnblogs.com/shiwei1930/p/11844323.html