pip list #

用法 #

python -m pip list [options]
					
py -m pip list [options]
					

描述 #

列出已安装的包,包括可编辑的。

Packages are listed in a case-insensitive sorted order.

选项 #

-o , --outdated #

List outdated packages

-u , --uptodate #

列出最新的包

-e , --editable #

列出可编辑工程。

-l , --local #

If in a virtualenv that has global access, do not list globally-installed packages.

--user #

Only output packages installed in user-site.

--path <path> #

Restrict to the specified installation path for listing packages (can be used multiple times).

--pre #

Include pre-release and development versions. By default, pip only finds stable versions.

--format <list_format> #

Select the output format among: columns (default), freeze, or json

--not-required #

List packages that are not dependencies of installed packages.

--exclude-editable #

Exclude editable package from output.

--include-editable #

Include editable package from output.

--exclude <package> #

Exclude specified package from the output

-i , --index-url <url> #

Base URL of the Python Package Index (default https://pypi.org/simple ). This should point to a repository compliant with PEP 503 (the simple repository API) or a local directory laid out in the same format.

--extra-index-url <url> #

Extra URLs of package indexes to use in addition to --index-url. Should follow the same rules as --index-url.

--no-index #

Ignore package index (only looking at --find-links URLs instead).

范例 #

  1. List installed packages (with the default column formatting).

    $ python -m pip list
    Package Version
    ------- -------
    docopt  0.6.2
    idlex   1.13
    jedi    0.9.0
    								
    C:\> py -m pip list
    Package Version
    ------- -------
    docopt  0.6.2
    idlex   1.13
    jedi    0.9.0
    								
  2. List outdated packages with column formatting.

    $ python -m pip list --outdated --format columns
    Package    Version Latest Type
    ---------- ------- ------ -----
    retry      0.8.1   0.9.1  wheel
    setuptools 20.6.7  21.0.0 wheel
    								
    C:\> py -m pip list --outdated --format columns
    Package    Version Latest Type
    ---------- ------- ------ -----
    retry      0.8.1   0.9.1  wheel
    setuptools 20.6.7  21.0.0 wheel
    								
  3. List packages that are not dependencies of other packages. Can be combined with other options.

    $ python -m pip list --outdated --not-required
    Package  Version Latest Type
    -------- ------- ------ -----
    docutils 0.14    0.17.1 wheel
    								
    C:\> py -m pip list --outdated --not-required
    Package  Version Latest Type
    -------- ------- ------ -----
    docutils 0.14    0.17.1 wheel
    								
  4. Use json formatting

    $ python -m pip list --format=json
    [{'name': 'colorama', 'version': '0.3.7'}, {'name': 'docopt', 'version': '0.6.2'}, ...
    								
    C:\> py -m pip list --format=json
    [{'name': 'colorama', 'version': '0.3.7'}, {'name': 'docopt', 'version': '0.6.2'}, ...
    								
  5. Use freeze formatting

    $ python -m pip list --format=freeze
    colorama==0.3.7
    docopt==0.6.2
    idlex==1.13
    jedi==0.9.0
    								
    C:\> py -m pip list --format=freeze
    colorama==0.3.7
    docopt==0.6.2
    idlex==1.13
    jedi==0.9.0
    								
  6. List packages installed in editable mode

When some packages are installed in editable mode, pip list outputs an additional column that shows the directory where the editable project is located (i.e. the directory that contains the pyproject.toml or setup.py file).

$ python -m pip list
Package          Version  Editable project location
---------------- -------- -------------------------------------
pip              21.2.4
pip-test-package 0.1.1    /home/you/.venv/src/pip-test-package
setuptools       57.4.0
wheel            0.36.2
						
C:\> py -m pip list
Package          Version  Editable project location
---------------- -------- ----------------------------------------
pip              21.2.4
pip-test-package 0.1.1    C:\Users\You\.venv\src\pip-test-package
setuptools       57.4.0
wheel            0.36.2
						

The json format outputs an additional editable_project_location 字段。

$ python -m pip list --format=json | python -m json.tool
[
  {
    "name": "pip",
    "version": "21.2.4",
  },
  {
    "name": "pip-test-package",
    "version": "0.1.1",
    "editable_project_location": "/home/you/.venv/src/pip-test-package"
  },
  {
    "name": "setuptools",
    "version": "57.4.0"
  },
  {
    "name": "wheel",
    "version": "0.36.2"
  }
]
						
C:\> py -m pip list --format=json | py -m json.tool
[
  {
    "name": "pip",
    "version": "21.2.4",
  },
  {
    "name": "pip-test-package",
    "version": "0.1.1",
    "editable_project_location": "C:\Users\You\.venv\src\pip-test-package"
  },
  {
    "name": "setuptools",
    "version": "57.4.0"
  },
  {
    "name": "wheel",
    "version": "0.36.2"
  }
]
						

注意

Contrary to the freeze 命令, pip list --format=freeze will not report editable install information, but the version of the package at the time it was installed.

内容