查找使用easy_install / pip安装的所有软件包?

本文翻译自:Find all packages installed with easy_install/pip?

Is there a way to find all Python PyPI packages that were installed with easy_install or pip? 有没有办法找到所有使用easy_install或pip安装的Python PyPI包? I mean, excluding everything that was/is installed with the distributions tools (in this case apt-get on Debian). 我的意思是,排除使用分发工具安装的所有内容(在本例中为apt-get on Debian)。


#1楼

参考:https://stackoom.com/question/RhBm/查找使用easy-install-pip安装的所有软件包


#2楼

The below is a little slow, but it gives a nicely formatted list of packages that pip is aware of. 下面有点慢,但它提供了一个格式良好的软件包列表, pip知道。 That is to say, not all of them were installed "by" pip, but all of them should be able to be upgraded by pip. 也就是说,并非所有这些都是“by”pip安装的,但所有这些都应该能够通过pip进行升级。

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

The reason it is slow is that it lists the contents of the entire pypi repo. 它很慢的原因是它列出了整个pypi仓库的内容。 I filed a ticket suggesting pip list provide similar functionality but more efficiently. 我提交了一张票据,建议pip list提供类似的功能,但效率更高。

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

#3楼

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). 如果Debian的行为类似于最近的关于pip install默认目标的Ubuntu版本,那就很容易了:它安装到/usr/local/lib/而不是/usr/libapt默认目标)。 Check https://askubuntu.com/questions/173323/how-do-i-detect-and-remove-python-packages-installed-via-pip/259747#259747 检查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. 我是ArchLinux用户,当我尝试使用pip时,我遇到了同样的问题。 Here's how I solved it in Arch. 这是我在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. 这里的关键是/usr/lib/python2.7/site-packages ,它是pip安装到的目录,YMMV。 pacman -Qo is how Arch's pac kage man ager checks for ownership of the file. pacman -Qo是Arch的pac kage man ager如何检查文件的所有权。 No package is part of the return it gives when no package owns the file: error: No package owns $FILENAME . 当没有包拥有该文件时,没有No package是它返回的一部分: 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 :( 棘手的解决方法:我正在查询__init__.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 ). 为了做其他发行版,你必须找出pip安装的东西(只是sudo pip install东西),如何查询文件的所有权(Debian / Ubuntu方法是dpkg -S )以及什么是“没有包”拥有该路径“返回(Debian / Ubuntu no path found matching pattern )。 Debian/Ubuntu users, beware: dpkg -S will fail if you give it a symbolic link. Debian / Ubuntu用户,请注意:如果给它一个符号链接, dpkg -S将失败。 Just resolve it first by using realpath . 首先使用realpath解决它。 Like this: 像这样:

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'

#4楼

As of version 1.3 of pip you can now use pip list 从点子版本1.3开始,您现在可以使用pip list

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/


#5楼

pip freeze lists all installed packages even if not by pip/easy_install. pip freeze列出了所有已安装的软件包,即使不是pip / easy_install也是如此。 On CentOs/Redhat a package installed through rpm is found. 在CentOs / Redhat上找到通过rpm安装的软件包。


#6楼

pip.get_installed_distributions() will give a list of installed packages pip.get_installed_distributions()将给出已安装包的列表

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值