Python pip 无法卸载 <package>:“这是一个安装了 distutils 的项目”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/53807511/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
pip cannot uninstall <package>: "It is a distutils installed project"
提问by rachelvsamuel
I tried to install the Twilio module:
我尝试安装 Twilio 模块:
sudo -H pip install twilio
And I got this error:
我收到了这个错误:
Installing collected packages: pyOpenSSL
Found existing installation: pyOpenSSL 0.13.1
Cannot uninstall 'pyOpenSSL'. It is a distutils installed project and
thus we cannot accurately determine which files belong to it which
would lead to only a partial uninstall.
Anyone know how to uninstall pyOpenSSL?
任何人都知道如何卸载 pyOpenSSL?
回答by ivan_pozdeev
This error means that this package's metadata doesn't include a list of files that belong to it. Most probably, you have installed this package via your OS' package manager, so you need to use that rather than pip
to update or remove it, too.
此错误意味着此包的元数据不包含属于它的文件列表。最有可能的是,您已经通过操作系统的软件包管理器安装了这个软件包,因此您也需要使用它而不是pip
更新或删除它。
See e.g. Upgrading to pip 10: It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall. · Issue #5247 · pypa/pipfor one such example where the package was installed with apt
.
参见例如升级到 pip 10:这是一个安装了 distutils 的项目,因此我们无法准确确定哪些文件属于它,这只会导致部分卸载。· 问题 #5247 · pypa/pip对于一个这样的例子,其中软件包是用apt
.
Alternatively, depending on your needs, it may be more productive to not use your system Python and/or its global environment but create a private Python installation and/or environment. There are many options here including virtualenv
, venv
, pyenv
, pipenv
and installing Python from source into
/usr/local
or $HOME
/$HOME/.local
(or /opt/<whatever>
).
或者,根据您的需要,不使用您的系统 Python 和/或其全局环境而创建私有 Python 安装和/或环境可能会更有效率。有很多选择,这里包括virtualenv
,venv
,pyenv
,pipenv
和从源代码安装Python的进入
/usr/local
或$HOME
/ $HOME/.local
(或/opt/<whatever>
)。
Finally, I must comment on the often-suggested (e.g. at pip 10 and apt: how to avoid "Cannot uninstall X" errors for distutils packages) --ignore-installed
pip
switch.
最后,我必须评论经常建议的(例如在pip 10 和 apt:如何避免 distutils 包的“无法卸载 X”错误)--ignore-installed
pip
开关。
It maywork (potentially for a long enough time for your business needs), but may just as well break things on the system in unpredictable ways. One thing is sure: it makes the system's configuration unsupported and thus unmaintainable -- because you have essentially overwritten files from your distribution with some other arbitrary stuff. E.g.:
它可能会起作用(可能在足够长的时间内满足您的业务需求),但也可能以不可预测的方式破坏系统上的事物。有一件事是肯定的:它使系统的配置不受支持,因此无法维护——因为您基本上已经用其他一些任意的东西覆盖了您的发行版中的文件。例如:
- If the new files are binary incompatible with the old ones, other software from the distribution built to link against the originals will segfault or otherwise malfunction.
- If the new version has a different set of files, you'll end up with a mix of old and new files which may break dependent software as well as the package itself.
- If you change the package with your OS' package manager later, it will overwrite
pip
-installed files, with similarly unpredictable results. - If there are things like configuration files, differences in them between the versions can also lead to all sorts of breakage.
- 如果新文件与旧文件的二进制文件不兼容,则发行版中为链接原始文件而构建的其他软件将出现段错误或其他故障。
- 如果新版本有一组不同的文件,您最终会混合使用新旧文件,这可能会破坏相关软件以及软件包本身。
- 如果您稍后使用操作系统的程序包管理器更改程序包,它将覆盖已
pip
安装的文件,同样会产生不可预测的结果。 - 如果有配置文件之类的东西,版本之间的差异也会导致各种损坏。