pipenv

Pipenv是pip和virtualenv的结合体,它可以更方便地创建和管理python虚拟环境。

Pipenv的基本用法如下:

1. 输出虚拟环境信息(可以验证当前目录的虚拟环境是否已经创建)

pipenv --venv

2. 创建虚拟环境

pipenv --python 3.7
pipenv --three

虚拟环境创建完成以后,会在当前目录下生成2个文件PipfilePipfile.lock

3. 移除虚拟环境

pipenv --rm

4. 安装依赖包

# 如安装flask包
pipenv install flask
# 在开发环境安装pytest
pipenv install pytest --dev

安装依赖包后,Pipfile中packages(或de v-packages)模块下会记录已安装的依赖包信息,Pipfile.lock中记录了依赖包的精确版本信息,它可以用来避免版本不一致引起的兼容性问题,建议不要手动更改Pipfile.lock文件内容。

5. 显示已安装的依赖包

pipenv graph

6. 检查安装的依赖包是否存在安全漏洞

pipenv check

7. 卸载依赖包

# 卸载指定包
pipenv uninstall flask
# 卸载所有依赖包
pipenv uninstall --all

8. 进入虚拟环境

pipenv shell

进入虚拟环境以后,执行python命令调用的就是虚拟环境中的python解释器,与系统安装的python环境就没有关系了。另外,进入虚拟环境后使用exit退出当前虚拟环境。

9. 查看python解释器路径

pipenv --py

10. 帮助

pipenv --help

通过pipenv的帮助手册可以查看更详细的用法。

Usage: pipenv [OPTIONS] COMMAND [ARGS]...

Options:
  --where             Output project home information.
  --venv              Output virtualenv information.
  --py                Output Python interpreter information.
  --envs              Output Environment Variable options.
  --rm                Remove the virtualenv.
  --bare              Minimal output.
  --completion        Output completion (to be eval'd).
  --man               Display manpage.
  --support           Output diagnostic information for use in GitHub issues.
  --site-packages     Enable site-packages for the virtualenv.  [env var:
                      PIPENV_SITE_PACKAGES]
  --python TEXT       Specify which version of Python virtualenv should use.
  --three / --two     Use Python 3/2 when creating virtualenv.
  --clear             Clears caches (pipenv, pip, and pip-tools).  [env var:
                      PIPENV_CLEAR]
  -v, --verbose       Verbose mode.
  --pypi-mirror TEXT  Specify a PyPI mirror.
  --version           Show the version and exit.
  -h, --help          Show this message and exit.


Usage Examples:
   Create a new project using Python 3.7, specifically:
   $ pipenv --python 3.7

   Remove project virtualenv (inferred from current directory):
   $ pipenv --rm

   Install all dependencies for a project (including dev):
   $ pipenv install --dev

   Create a lockfile containing pre-releases:
   $ pipenv lock --pre

   Show a graph of your installed dependencies:
   $ pipenv graph

   Check your installed dependencies for security vulnerabilities:
   $ pipenv check

   Install a local setup.py into your virtual environment/Pipfile:
   $ pipenv install -e .

   Use a lower-level pip command:
   $ pipenv run pip freeze

Commands:
  check      Checks for security vulnerabilities and against PEP 508 markers
             provided in Pipfile.
  clean      Uninstalls all packages not specified in Pipfile.lock.
  graph      Displays currently-installed dependency graph information.
  install    Installs provided packages and adds them to Pipfile, or (if no
             packages are given), installs all packages from Pipfile.
  lock       Generates Pipfile.lock.
  open       View a given module in your editor.
  run        Spawns a command installed into the virtualenv.
  shell      Spawns a shell within the virtualenv.
  sync       Installs all packages specified in Pipfile.lock.
  uninstall  Un-installs a provided package and removes it from Pipfile.
  update     Runs lock, then sync.

你可能感兴趣的:(pipenv)