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

发布于 2025-01-08 05:36:01 字数 230 浏览 1 评论 0原文

我正在尝试删除所有已安装的“pyobjc-framework”前缀包。我已经尝试了以下操作:

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

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

请在我必须手动分解并卸载其中每个之前提供帮助!没有人想要这样。

I am attempting to remove all of the installed "pyobjc-framework"-prefixed packages. I have tried the following:

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

but this barfs because each pip uninstall requires confirmation (perhaps a way to bypass this would be a solution).

Please help before I have to break down and uninstall each of these manually! Nobody wants that.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

微暖i 2025-01-15 05:36:01

如果您添加 -y | 您的命令实际上应该有效。 --yes 标记为 pip :-)

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

可能:

% pip freeze | grep pyobjc 框架 | xargs pip uninstall -y

Your command should actually work if you add the -y | --yes flag to pip :-)

-y, --yes Don't ask for confirmation of uninstall deletions.

Possibly:

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

寄居者 2025-01-15 05:36:01

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

pip uninstall -r <file name>

我认为有效。

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

Redirect the grep output to a new file and run.

pip uninstall -r <file name>

works I think.

pip freeze | grep pyobjc > packages_to_remove.txt
sudo pip uninstall -y -r packages_to_remove.txt
迷途知返 2025-01-15 05:36:01

我总是用这个:

pip freeze | xargs pip uninstall -y

I always use this:

pip freeze | xargs pip uninstall -y
风吹过旳痕迹 2025-01-15 05:36:01

最简单的方法。使用删除所有与 torch 相关的包,例如:

pip uninstall `pip freeze | grep torch`

Easiest way. use remove all torch related packages for example:

pip uninstall `pip freeze | grep torch`
你爱我像她 2025-01-15 05:36:01

只需将这些包准备为列表即可:

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. show dependency list
  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

Just prepare those packages as list:

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 

For example: Uninstall package with its dependence with pip in three steps:

  1. show dependence list
  2. remove the package
  3. remove list of its dependence (copy it from 1.)

For detail:

 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
过气美图社 2025-01-15 05:36:01

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

greping pip freeze returned:

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

no such option: -e

So I did it with pip list instead:

$ 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
拥抱没勇气 2025-01-15 05:36:01

执行pip uninstall -y -r <(pip freeze)

Do pip uninstall -y -r <(pip freeze)

独闯女儿国 2025-01-15 05:36:01
您可以结合使用 pip freezegrepawk 命令来卸载以某些字符开头的软件包。

以下是卸载以 PyQt 开头的软件包的示例:

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

这将删除以 PyQt 开头的每个软件包。

如果您想立即卸载所有软件包,可以执行以下操作:
pip freeze | xargs pip uninstall -y

这将从 pip 中删除每个软件包。

You can uninstall packages that start with certain characters using a combination of pip freeze, grep, and awk commands.

Here's an example for uninstalling packages that start with PyQt:

  • if you want to see the packages before:
pip freeze | grep -E '^PyQt'
  • then uninstall:
pip freeze | grep -E '^PyQt' | awk -F'==' '{print $1}' | xargs pip uninstall -y

This will remove every package that starts with PyQt.

If you want to uninstall all packages at once, you can do so with the following:
pip freeze | xargs pip uninstall -y

This will remove every package from pip.

pip freeze 输出的一个问题是它不能很好地解析使用 --editable/-e 安装的软件包标志,因为“-e”标志(如果在 git 存储库中,则可能后跟源 git URL)将出现在冻结列表中而不是包名称,例如:

-e packages/my_package
-e git+ssh://[email protected]/your/project.git@abcdebd5c7d5fb53fdd7f79a4a719b3999a3dceb#egg=my_package&subdirectory=packages/my_package

在这种情况下,而不是尝试提取包名称,使用 pip 更简单、更可靠list 而不是 pip freeze,因为这将输出包名称,而不是它们的源:

$ pip uninstall -y $(pip list | awk '{print $1}' | grep -E '^PyQt')

或者如果您更喜欢 cut

$ pip uninstall -y $(pip list | cut -d ' ' -f 1 | grep -E '^PyQt')

A problem with the pip freeze output is that it doesn't parse so well with packages that were installed with the --editable/-e flag, because the "-e" flag (perhaps followed by source git URL if in a git repository) will appear in the freeze list instead of the package name, such as:

-e packages/my_package
-e git+ssh://[email protected]/your/project.git@abcdebd5c7d5fb53fdd7f79a4a719b3999a3dceb#egg=my_package&subdirectory=packages/my_package

In this case, rather than trying to extract the package name, it's simpler and more reliable to use pip list instead of pip freeze, as this will output the package names, not their source:

$ pip uninstall -y $(pip list | awk '{print $1}' | grep -E '^PyQt')

Or if you prefer cut:

$ pip uninstall -y $(pip list | cut -d ' ' -f 1 | grep -E '^PyQt')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文