有没有办法用pip卸载多个包?

问题描述 投票:0回答:8

我正在尝试删除所有已安装的带有“pyobjc-framework”前缀的软件包。我尝试过以下方法:

% pip freeze | grep pyobjc-framework | xargs pip uninstall

但是这个 barfs 因为每个 pip 卸载都需要确认(也许绕过这个的方法是一个解决方案)。

请在我必须手动分解和卸载它们之前提供帮助!没有人想要这样。

python pip xargs
8个回答
78
投票

如果您将

-y | --yes
标志添加到 pip 中,您的命令实际上应该有效:-)

-y, --yes 不要求确认卸载删除。

可能:

% pip freeze | grep pyobjc-framework | xargs pip uninstall -y


16
投票

将 grep 输出重定向到新文件并运行。

pip uninstall -r <file name>

我认为有效。

pip freeze | grep pyobjc > packages_to_remove.txt
sudo pip uninstall -y -r packages_to_remove.txt

10
投票

我一直用这个:

pip freeze | xargs pip uninstall -y

6
投票

最简单的方法。使用删除所有

torch
相关软件包,例如:

pip uninstall `pip freeze | grep torch`

3
投票

只需按照清单准备这些包裹即可:

pip uninstall <list of requirement> -y
e.g.:
pip uninstall  termcolor, imgviz, matplotlib, PyYAML, qtpy, Pillow, colorama, PyQt5, numpy -y
(Some version of pip require to remove commas, s. below)
pip uninstall termcolor imgviz matplotlib -y 

例如:用pip卸载包及其依赖,分三步:

  1. 显示依赖列表
  2. 取出包装
  3. 删除其依赖列表(从1复制。)

详情:

 1. pip show <package>

    e.g.:
    pip show labelme
    ...
    Requires: termcolor, imgviz, matplotlib, PyYAML, qtpy, Pillow, colorama, PyQt5, numpy
    ...

 2. pip uninstall <package>
    e.g.
    pip uninstall labelme

 3. pip uninstall <list of requirement> -y
    e.g.:
    pip uninstall  termcolor, imgviz, matplotlib, PyYAML, qtpy, Pillow, colorama, PyQt5, numpy -y

1
投票

greping

pip freeze
返回:

Usage:   
  pip uninstall [options] <package> ...
  pip uninstall [options] -r <requirements file> ...

no such option: -e

所以我用

pip list
来代替:

$ pip list | grep tempest | xargs pip uninstall -y

Uninstalling neutron-tempest-plugin-0.0.0:
  Successfully uninstalled neutron-tempest-plugin-0.0.0
Uninstalling octavia-tempest-plugin-0.0.0:
  Successfully uninstalled octavia-tempest-plugin-0.0.0
Uninstalling tempest-19.0.1.dev152:
  Successfully uninstalled tempest-19.0.1.dev152

1
投票

pip uninstall -y -r <(pip freeze)


0
投票

您可以使用

pip freeze
grep
awk
命令的组合来卸载以某些字符开头的软件包。 以下是卸载以
PyQt
开头的软件包的示例:

  • 如果您想查看之前的包裹:
pip freeze | grep -E '^PyQt'
  • 然后卸载:
pip freeze | grep -E '^PyQt' | awk -F'==' '{print $1}' | xargs pip uninstall -y

这将删除所有以

PyQt
开头的包。

© www.soinside.com 2019 - 2024. All rights reserved.