如何卸载使用 pip install --user 安装的软件包 [英] How to uninstall a package installed with pip install --user

查看:61
本文介绍了如何卸载使用 pip install --user 安装的软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

pip 有一个 --user 选项,可以为每个用户安装一个 Python 包:

There is a --user option for pip which can install a Python package per user:

pip install --user [python-package-name]

我使用此选项在我没有 root 访问权限的服务器上安装软件包.我现在需要的是卸载当前用户安装的包.我试图执行这个命令:

I used this option to install a package on a server for which I do not have root access. What I need now is to uninstall the installed package on the current user. I tried to execute this command:

pip uninstall --user [python-package-name]

但我得到了:

no such option: --user

除了手动查找和删除软件包之外,如何卸载使用 pip install --user 安装的软件包?

How can I uninstall a package that I installed with pip install --user, other than manually finding and deleting the package?

我找到了这篇文章

pip 无法从每个用户的站点包目录中卸载

描述不支持从用户目录卸载包.根据文章,如果正确实施,则使用

which describes that uninstalling packages from user directory does not supported. According to the article if it was implemented correctly then with

pip uninstall [package-name]

安装的包也会在用户目录中搜索.但对我来说仍然存在一个问题.如果在系统范围内和每个用户都安装了相同的软件包怎么办?如果有人需要定位特定的用户目录怎么办?

the package that was installed will be also searched in user directories. But a problem still remains for me. What if the same package was installed both system-wide and per-user? What if someone needs to target a specific user directory?

推荐答案

在 Linux 上使用 Python 3.5 和 pip 7.1.2 对此进行了测试,情况似乎是这样的:

Having tested this using Python 3.5 and pip 7.1.2 on Linux, the situation appears to be this:

  • pip install --user somepackage 安装到 $HOME/.local,使用 pip uninstall somepackage 卸载它确实有效.

  • pip install --user somepackage installs to $HOME/.local, and uninstalling it does work using pip uninstall somepackage.

无论 somepackage 是否同时在系统范围内安装都是如此.

This is true whether or not somepackage is also installed system-wide at the same time.

如果两个地方都安装了这个包,只会卸载本地一个.要使用 pip 在系统范围内卸载软件包,首先在本地卸载它,然后再次运行相同的卸载命令,使用 root 权限.

If the package is installed at both places, only the local one will be uninstalled. To uninstall the package system-wide using pip, first uninstall it locally, then run the same uninstall command again, with root privileges.

除了预定义的用户安装目录外,pip install --target somedir somepackage 会将软件包安装到 somedir 中.无法使用 pip 从这样的地方卸载软件包.(但是 Github 上有一个有点旧的未合并的 pull request 实现了 pip uninstall --target.)

In addition to the predefined user install directory, pip install --target somedir somepackage will install the package into somedir. There is no way to uninstall a package from such a place using pip. (But there is a somewhat old unmerged pull request on Github that implements pip uninstall --target.)

由于 pip 将卸载的唯一位置是系统范围和预定义的用户本地,您需要以相应用户身份运行 pip uninstall从给定用户的本地安装目录卸载.

Since the only places pip will ever uninstall from are system-wide and predefined user-local, you need to run pip uninstall as the respective user to uninstall from a given user's local install directory.

这篇关于如何卸载使用 pip install --user 安装的软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆