查找安装了easy_install/pip的所有包?

时间:2021-02-27 21:37:30

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 tools (in this case apt-get on Debian).

是否有一种方法可以找到安装了easy_install或pip的所有Python PyPI包?我的意思是,不包括所有与发行工具(在本例中是apt-get on Debian)安装的所有内容。

15 个解决方案

#1


317  

pip freeze will output a list of installed packages and their versions. It also allows you to write those packages to a file that can later be used to set up a new environment.

pip冻结将输出已安装包及其版本的列表。它还允许您将这些包写到一个文件中,该文件稍后可用于设置新环境。

https://pip.pypa.io/en/stable/reference/pip_freeze/#pip-freeze

https://pip.pypa.io/en/stable/reference/pip_freeze/ pip-freeze

#2


215  

As of version 1.3 of pip you can now use pip list

在pip的1.3版本中,您现在可以使用pip列表

It has some useful options including the ability to show outdated packages. Here's the documentation: https://pip.pypa.io/en/latest/reference/pip_list/

它有一些有用的选项,包括显示过期包的功能。这是文档:https://pip.pypa.io/en/latest/reference/pip_list/

#3


127  

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

如果有人想知道,您可以使用“pip show”命令。

pip show [options] <package>

This will list the install directory of the given package.

这将列出给定包的安装目录。

#4


21  

If Debian behaves like recent Ubuntu versions regarding pip install default target, it's dead easy: it installs to /usr/local/lib/ instead of /usr/lib (apt default target). Check https://askubuntu.com/questions/173323/how-do-i-detect-and-remove-python-packages-installed-via-pip/259747#259747

如果Debian对pip安装默认目标的Ubuntu版本有类似的行为,那么它就非常简单:它安装到/usr/local/lib/而不是/usr/lib (apt默认目标)。检查https://askubuntu.com/questions/173323/how-do-i-detect-and-remove-python-packages-installed-via-pip/259747 # 259747

I am an ArchLinux user and as I experimented with pip I met this same problem. Here's how I solved it in Arch.

我是一个ArchLinux用户,当我尝试pip时,我遇到了同样的问题。这是我用Arch解出来的。

find /usr/lib/python2.7/site-packages -maxdepth 2 -name __init__.py | xargs pacman -Qo | grep 'No package'

Key here is /usr/lib/python2.7/site-packages, which is the directory pip installs to, YMMV. pacman -Qo is how Arch's pac kage man ager checks for ownership of the file. No package is part of the return it gives when no package owns the file: error: No package owns $FILENAME. Tricky workaround: I'm querying about __init__.py because pacman -Qo is a little bit ignorant when it comes to directories :(

这里的关键是/usr/lib/python2.7/site-packages,它是pip安装到YMMV的目录。pacman -Qo是Arch的pac - man ager检查文件所有权的方式。当没有包拥有文件时,没有包是返回的一部分:error:没有包拥有$FILENAME。棘手的解决办法:我在问关于……py因为pacman -Qo对于目录有点无知

In order to do it for other distros, you have to find out where pip installs stuff (just sudo pip install something), how to query ownership of a file (Debian/Ubuntu method is dpkg -S) and what is the "no package owns that path" return (Debian/Ubuntu is no path found matching pattern). Debian/Ubuntu users, beware: dpkg -S will fail if you give it a symbolic link. Just resolve it first by using realpath. Like this:

为了做其他的发行版,你必须找出pip安装东西(sudo pip安装的东西),如何查询文件的所有权(Debian / Ubuntu方法dpkg - s),什么是“不”包拥有该路径返回(Debian / Ubuntu是没有发现路径匹配模式)。Debian/Ubuntu用户,注意:如果你给它一个符号链接,dpkg -S将会失败。首先使用realpath解决它。是这样的:

find /usr/local/lib/python2.7/dist-packages -maxdepth 2 -name __init__.py | xargs realpath | xargs dpkg -S 2>&1 | grep 'no path found'

Fedora users can try (thanks @eddygeek):

Fedora用户可以尝试(感谢@eddygeek):

find /usr/lib/python2.7/site-packages -maxdepth 2 -name __init__.py | xargs rpm -qf | grep 'not owned by any package'

#5


10  

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.

点击这里获取更多关于pip显示的信息,在这里获取更多关于pip列表的信息。

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    

#6


6  

pip.get_installed_distributions() will give a list of installed packages

get_installed_()将给出已安装包的列表。

import pip
from os.path import join

for package in pip.get_installed_distributions():
    print(package.location) # you can exclude packages that's in /usr/XXX
    print(join(package.location, package._get_metadata("top_level.txt"))) # root directory of this package

#7


6  

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知道的格式良好的包列表。也就是说,不是所有的设备都是由pip安装的,但是所有的设备都应该能够通过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.

它慢的原因是它列出了整个pypi repo的内容。我提出了一个建议,建议pip列表提供类似的功能,但更有效。

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)
$

#8


4  

Take note that if you have multiple versions of Python installed on your computer, you may have a few versions of pip associated with each.

请注意,如果您的计算机上安装了多个版本的Python,那么可能会有几个版本的pip与每个版本相关联。

Depending on your associations, you might need to be very cautious of what pip command you use:

根据您的关联,您可能需要非常谨慎地使用pip命令:

pip3 list 

Worked for me, where I'm running Python3.4. Simply using pip list returned the error The program 'pip' is currently not installed. You can install it by typing: sudo apt-get install python-pip.

为我工作,运行Python3.4。简单地使用pip列表返回错误,程序“pip”当前没有安装。您可以通过键入:sudo apt-get安装python-pip来安装它。

#9


3  

Adding to @Paul Woolcock's answer,

加上@Paul Woolcock的回答,

$ pip freeze > requirements.txt

will create a requirements file with all installed packages in the active environment at the current location which you can run

是否将在当前运行的活动环境中创建一个包含所有已安装包的需求文件

$ pip install -r requirements.txt

to install the requirements at another environment.

在另一个环境中安装需求。

#10


3  

Newer versions of pip have the ability to do what the OP wants via pip list -l or pip freeze -l. On Debian (at least) the man page doesn't make this clear, and I only discovered it - under the assumption that the feature must exist - with pip list --help.

更新版本的pip可以通过pip列表-l或pip冻结-l实现OP所需的功能。在Debian(至少)中,手册页没有说明这一点,我只是在假定该特性必须存在的情况下(使用pip列表)发现了它的帮助。

There are recent comments that suggest this feature is not obvious in either the documentation or the existing answers (although hinted at by some), so I thought I should post. I would have preferred to do so as a comment, but I don't have the reputation points.

最近有一些评论指出,这个特性在文档或现有答案中都不明显(尽管有些人暗示),所以我认为我应该发布它。我更愿意这样做作为一个评论,但我没有声誉点。

#11


2  

Here is the one-liner for fedora or other rpm distros (based on @barraponto tips):

以下是fedora或其他rpm发行版的一行代码(基于@barraponto tips):

find /usr/lib/python2.7/site-packages -maxdepth 2 -name __init__.py | xargs rpm -qf | grep 'not owned by any package'

Append this to the previous command to get cleaner output:

将此附加到前面的命令以获得更清晰的输出:

 | sed -r 's:.*/(\w+)/__.*:\1:'

#12


1  

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.

获取站点包/(以及分区包/如果存在的话)中的所有文件/文件夹名称,并使用包管理器删除通过包安装的文件/文件夹名称。

#13


1  

pip freeze lists all installed packages even if not by pip/easy_install. On CentOs/Redhat a package installed through rpm is found.

pip冻结列出所有已安装的包,即使不是通过pip/easy_install。在CentOs/Redhat中发现了一个通过rpm安装的软件包。

#14


0  

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

至少对于Ubuntu(也许还有其他人)来说是这样的(灵感来自于之前的一篇文章):

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

#15


0  

If you use the Anaconda python distribution, you can use the conda list command to see what was installed by what method:

如果您使用Anaconda python发行版,您可以使用conda list命令查看通过什么方法安装的内容:

user@pc:~ $ conda list
# packages in environment at /anaconda3:
#
# Name                    Version                   Build  Channel
_ipyw_jlab_nb_ext_conf    0.1.0            py36h2fc01ae_0
alabaster                 0.7.10           py36h174008c_0
amqp                      2.2.2                     <pip>
anaconda                  5.1.0                    py36_2
anaconda-client           1.6.9                    py36_0

To grab the entries installed by pip (including possibly pip itself):

获取pip安装的条目(包括pip本身):

user@pc:~ $ conda list | grep \<pip
amqp                      2.2.2                     <pip>
astroid                   1.6.2                     <pip>
billiard                  3.5.0.3                   <pip>
blinker                   1.4                       <pip>
ez-setup                  0.9                       <pip>
feedgenerator             1.9                       <pip>

Of course you probably want to just select the first column, which you can do with (excluding pip if needed):

当然,您可能只想选择第一列,这是您可以做的(如果需要的话,不包括pip):

user@pc:~ $ conda list | awk '$3 ~ /pip/ {if ($1 != "pip") print $1}'
amqp        
astroid
billiard
blinker
ez-setup
feedgenerator 

Finally you can grab these values and pip uninstall all of them using the following:

最后,您可以获取这些值并使用以下方法卸载它们:

user@pc:~ $ conda list | awk '$3 ~ /pip/ {if ($1 != "pip") print $1}' | xargs pip uninstall -y

Note the use of the -y flag for the pip uninstall to avoid having to give confirmation to delete.

注意,pip卸载使用-y标志,以避免必须给出要删除的确认。

#1


317  

pip freeze will output a list of installed packages and their versions. It also allows you to write those packages to a file that can later be used to set up a new environment.

pip冻结将输出已安装包及其版本的列表。它还允许您将这些包写到一个文件中,该文件稍后可用于设置新环境。

https://pip.pypa.io/en/stable/reference/pip_freeze/#pip-freeze

https://pip.pypa.io/en/stable/reference/pip_freeze/ pip-freeze

#2


215  

As of version 1.3 of pip you can now use pip list

在pip的1.3版本中,您现在可以使用pip列表

It has some useful options including the ability to show outdated packages. Here's the documentation: https://pip.pypa.io/en/latest/reference/pip_list/

它有一些有用的选项,包括显示过期包的功能。这是文档:https://pip.pypa.io/en/latest/reference/pip_list/

#3


127  

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

如果有人想知道,您可以使用“pip show”命令。

pip show [options] <package>

This will list the install directory of the given package.

这将列出给定包的安装目录。

#4


21  

If Debian behaves like recent Ubuntu versions regarding pip install default target, it's dead easy: it installs to /usr/local/lib/ instead of /usr/lib (apt default target). Check https://askubuntu.com/questions/173323/how-do-i-detect-and-remove-python-packages-installed-via-pip/259747#259747

如果Debian对pip安装默认目标的Ubuntu版本有类似的行为,那么它就非常简单:它安装到/usr/local/lib/而不是/usr/lib (apt默认目标)。检查https://askubuntu.com/questions/173323/how-do-i-detect-and-remove-python-packages-installed-via-pip/259747 # 259747

I am an ArchLinux user and as I experimented with pip I met this same problem. Here's how I solved it in Arch.

我是一个ArchLinux用户,当我尝试pip时,我遇到了同样的问题。这是我用Arch解出来的。

find /usr/lib/python2.7/site-packages -maxdepth 2 -name __init__.py | xargs pacman -Qo | grep 'No package'

Key here is /usr/lib/python2.7/site-packages, which is the directory pip installs to, YMMV. pacman -Qo is how Arch's pac kage man ager checks for ownership of the file. No package is part of the return it gives when no package owns the file: error: No package owns $FILENAME. Tricky workaround: I'm querying about __init__.py because pacman -Qo is a little bit ignorant when it comes to directories :(

这里的关键是/usr/lib/python2.7/site-packages,它是pip安装到YMMV的目录。pacman -Qo是Arch的pac - man ager检查文件所有权的方式。当没有包拥有文件时,没有包是返回的一部分:error:没有包拥有$FILENAME。棘手的解决办法:我在问关于……py因为pacman -Qo对于目录有点无知

In order to do it for other distros, you have to find out where pip installs stuff (just sudo pip install something), how to query ownership of a file (Debian/Ubuntu method is dpkg -S) and what is the "no package owns that path" return (Debian/Ubuntu is no path found matching pattern). Debian/Ubuntu users, beware: dpkg -S will fail if you give it a symbolic link. Just resolve it first by using realpath. Like this:

为了做其他的发行版,你必须找出pip安装东西(sudo pip安装的东西),如何查询文件的所有权(Debian / Ubuntu方法dpkg - s),什么是“不”包拥有该路径返回(Debian / Ubuntu是没有发现路径匹配模式)。Debian/Ubuntu用户,注意:如果你给它一个符号链接,dpkg -S将会失败。首先使用realpath解决它。是这样的:

find /usr/local/lib/python2.7/dist-packages -maxdepth 2 -name __init__.py | xargs realpath | xargs dpkg -S 2>&1 | grep 'no path found'

Fedora users can try (thanks @eddygeek):

Fedora用户可以尝试(感谢@eddygeek):

find /usr/lib/python2.7/site-packages -maxdepth 2 -name __init__.py | xargs rpm -qf | grep 'not owned by any package'

#5


10  

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.

点击这里获取更多关于pip显示的信息,在这里获取更多关于pip列表的信息。

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    

#6


6  

pip.get_installed_distributions() will give a list of installed packages

get_installed_()将给出已安装包的列表。

import pip
from os.path import join

for package in pip.get_installed_distributions():
    print(package.location) # you can exclude packages that's in /usr/XXX
    print(join(package.location, package._get_metadata("top_level.txt"))) # root directory of this package

#7


6  

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知道的格式良好的包列表。也就是说,不是所有的设备都是由pip安装的,但是所有的设备都应该能够通过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.

它慢的原因是它列出了整个pypi repo的内容。我提出了一个建议,建议pip列表提供类似的功能,但更有效。

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)
$

#8


4  

Take note that if you have multiple versions of Python installed on your computer, you may have a few versions of pip associated with each.

请注意,如果您的计算机上安装了多个版本的Python,那么可能会有几个版本的pip与每个版本相关联。

Depending on your associations, you might need to be very cautious of what pip command you use:

根据您的关联,您可能需要非常谨慎地使用pip命令:

pip3 list 

Worked for me, where I'm running Python3.4. Simply using pip list returned the error The program 'pip' is currently not installed. You can install it by typing: sudo apt-get install python-pip.

为我工作,运行Python3.4。简单地使用pip列表返回错误,程序“pip”当前没有安装。您可以通过键入:sudo apt-get安装python-pip来安装它。

#9


3  

Adding to @Paul Woolcock's answer,

加上@Paul Woolcock的回答,

$ pip freeze > requirements.txt

will create a requirements file with all installed packages in the active environment at the current location which you can run

是否将在当前运行的活动环境中创建一个包含所有已安装包的需求文件

$ pip install -r requirements.txt

to install the requirements at another environment.

在另一个环境中安装需求。

#10


3  

Newer versions of pip have the ability to do what the OP wants via pip list -l or pip freeze -l. On Debian (at least) the man page doesn't make this clear, and I only discovered it - under the assumption that the feature must exist - with pip list --help.

更新版本的pip可以通过pip列表-l或pip冻结-l实现OP所需的功能。在Debian(至少)中,手册页没有说明这一点,我只是在假定该特性必须存在的情况下(使用pip列表)发现了它的帮助。

There are recent comments that suggest this feature is not obvious in either the documentation or the existing answers (although hinted at by some), so I thought I should post. I would have preferred to do so as a comment, but I don't have the reputation points.

最近有一些评论指出,这个特性在文档或现有答案中都不明显(尽管有些人暗示),所以我认为我应该发布它。我更愿意这样做作为一个评论,但我没有声誉点。

#11


2  

Here is the one-liner for fedora or other rpm distros (based on @barraponto tips):

以下是fedora或其他rpm发行版的一行代码(基于@barraponto tips):

find /usr/lib/python2.7/site-packages -maxdepth 2 -name __init__.py | xargs rpm -qf | grep 'not owned by any package'

Append this to the previous command to get cleaner output:

将此附加到前面的命令以获得更清晰的输出:

 | sed -r 's:.*/(\w+)/__.*:\1:'

#12


1  

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.

获取站点包/(以及分区包/如果存在的话)中的所有文件/文件夹名称,并使用包管理器删除通过包安装的文件/文件夹名称。

#13


1  

pip freeze lists all installed packages even if not by pip/easy_install. On CentOs/Redhat a package installed through rpm is found.

pip冻结列出所有已安装的包,即使不是通过pip/easy_install。在CentOs/Redhat中发现了一个通过rpm安装的软件包。

#14


0  

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

至少对于Ubuntu(也许还有其他人)来说是这样的(灵感来自于之前的一篇文章):

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

#15


0  

If you use the Anaconda python distribution, you can use the conda list command to see what was installed by what method:

如果您使用Anaconda python发行版,您可以使用conda list命令查看通过什么方法安装的内容:

user@pc:~ $ conda list
# packages in environment at /anaconda3:
#
# Name                    Version                   Build  Channel
_ipyw_jlab_nb_ext_conf    0.1.0            py36h2fc01ae_0
alabaster                 0.7.10           py36h174008c_0
amqp                      2.2.2                     <pip>
anaconda                  5.1.0                    py36_2
anaconda-client           1.6.9                    py36_0

To grab the entries installed by pip (including possibly pip itself):

获取pip安装的条目(包括pip本身):

user@pc:~ $ conda list | grep \<pip
amqp                      2.2.2                     <pip>
astroid                   1.6.2                     <pip>
billiard                  3.5.0.3                   <pip>
blinker                   1.4                       <pip>
ez-setup                  0.9                       <pip>
feedgenerator             1.9                       <pip>

Of course you probably want to just select the first column, which you can do with (excluding pip if needed):

当然,您可能只想选择第一列,这是您可以做的(如果需要的话,不包括pip):

user@pc:~ $ conda list | awk '$3 ~ /pip/ {if ($1 != "pip") print $1}'
amqp        
astroid
billiard
blinker
ez-setup
feedgenerator 

Finally you can grab these values and pip uninstall all of them using the following:

最后,您可以获取这些值并使用以下方法卸载它们:

user@pc:~ $ conda list | awk '$3 ~ /pip/ {if ($1 != "pip") print $1}' | xargs pip uninstall -y

Note the use of the -y flag for the pip uninstall to avoid having to give confirmation to delete.

注意,pip卸载使用-y标志,以避免必须给出要删除的确认。