Find all packages installed with easy_install/pip?

前端 未结 18 1083
醉话见心
醉话见心 2020-11-27 08:47

Is there a way to find all Python PyPI packages that were installed with easy_install or pip? I mean, excluding everything that was/is installed with the distributions tool

相关标签:
18条回答
  • 2020-11-27 09:24

    Start with:

    $ pip list
    

    To list all packages. Once you found the package you want, use:

    $ pip show <package-name>
    

    This will show you details about this package, including its folder. You can skip the first part if you already know the package name

    Click here for more information on pip show and here for more information on pip list.

    Example:

    $ pip show jupyter
    Name: jupyter
    Version: 1.0.0
    Summary: Jupyter metapackage. Install all the Jupyter components in one go.
    Home-page: http://jupyter.org
    Author: Jupyter Development Team
    Author-email: jupyter@googlegroups.org
    License: BSD
    Location: /usr/local/lib/python2.7/site-packages
    Requires: ipywidgets, nbconvert, notebook, jupyter-console, qtconsole, ipykernel    
    
    0 讨论(0)
  • 2020-11-27 09:30

    The below is a little slow, but it gives a nicely formatted list of packages that pip is aware of. That is to say, not all of them were installed "by" pip, but all of them should be able to be upgraded by pip.

    $ pip search . | egrep -B1 'INSTALLED|LATEST'
    

    The reason it is slow is that it lists the contents of the entire pypi repo. I filed a ticket suggesting pip list provide similar functionality but more efficiently.

    Sample output: (restricted the search to a subset instead of '.' for all.)

    $ pip search selenium | egrep -B1 'INSTALLED|LATEST'
    
    selenium                  - Python bindings for Selenium
      INSTALLED: 2.24.0
      LATEST:    2.25.0
    --
    robotframework-selenium2library - Web testing library for Robot Framework
      INSTALLED: 1.0.1 (latest)
    $
    
    0 讨论(0)
  • 2020-11-27 09:32

    If anyone is wondering you can use the 'pip show' command.

    pip show [options] <package>
    

    This will list the install directory of the given package.

    0 讨论(0)
  • Get all file/folder names in site-packages/ (and dist-packages/ if it exists), and use your package manager to strip the ones that were installed via package.

    0 讨论(0)
  • 2020-11-27 09:34

    At least for Ubuntu (maybe also others) works this (inspired by a previous post in this thread):

    printf "Installed with pip:";
    pip list 2>/dev/null | gawk '{print $1;}' | while read; do pip show "${REPLY}" 2>/dev/null | grep 'Location: /usr/local/lib/python2.7/dist-packages' >/dev/null; if (( $? == 0 )); then printf " ${REPLY}"; fi; done; echo
    
    0 讨论(0)
  • 2020-11-27 09:37

    For those who don't have pip installed, I found this quick script on github (works with Python 2.7.13):

    import pkg_resources
    distros = pkg_resources.AvailableDistributions()
    for key in distros:
      print distros[key]
    
    0 讨论(0)
提交回复
热议问题