如何升级 disutils 包 PyYAML?

How to upgrade disutils package PyYAML?

我正在尝试安装 chatterbot,它依赖于 PyYAML=3.12。在我的 Ubuntu 机器上安装的 PyYAML 版本是 3.11。所以我用下面的命令升级了PyYAML:

sudo -H pip3 install --upgrade PyYAML

但它给出了以下错误:

Cannot uninstall 'PyYAML'. 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.

我的pip3版本是10.0.0.

如何解决?

我发现 in this Github issue pip 10 不再卸载 distutils 包。所以我降级到 pip 8.1.1。现在可以了。

如果正在查看此问题的任何人知道如何使用 pip 10.0.0 卸载或升级 distutils 软件包,请在此处告诉我。 :)

(如果有人需要)
为了降级 pip,我使用了以下内容:

sudo -H pip3 install pip==8.1.1

尝试使用 --ignore-installed 标志:

sudo -H pip3 install --ignore-installed PyYAML

之所以可行,是因为要升级软件包,pip 首先卸载旧版本,然后安装新版本。这是 distutils 包失败的卸载步骤。使用 --ignore-installed 标志,跳过卸载步骤,新版本简单地安装在旧版本之上。

问题:

Cannot uninstall 'PyYAML'. 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.

解决方案:删除 Dist 包和 运行

sudo rm -rf /usr/lib/python3/dist-packages/yaml

sudo rm -rf /usr/lib/python3/dist-packages/PyYAML-*

从 distutils 中删除文件夹有效

我个人在 anaconda 上安装了 PyYAML,只需执行 'conda remove PyYAML' 然后执行我的 pip 命令就可以了。

你可以试试这个:

$pip install --ignore-installed PyYAML

我遇到了类似的问题,其中 PyYAML 软件包是由 conda 安装的。还有另一个使用 conda remove.

的答案

相反,我使用 conda update PyYAML 解决了这个问题,有效地使用 conda 更新 pip 尝试自行更新的依赖项。

conda remove PyYAML

conda 删除需要时间

pip install chatterbot
pip install chatterbot_corpus

这样它解决了我在尝试时的错误 from chatterbot import chatbot

我只需要卸载 python3-yaml 并再次尝试使用 pip

sudo apt-get purge python3-yaml

如果 --ignore-installed 不是您的情况,而您 运行宁 Debian/Ubuntu,那么您可以尝试以下解决方案。

PyYAML 可能与 apt 一起安装,作为另一个包的依赖项。

调试:

  1. 检测包名称:运行 apt list --installed | grep python 并搜索任何 yaml 事件。
  2. 假设您检测到一个包裹 python3-yaml
  3. 搜索反向依赖:apt-cache rdepends --installed python3-yaml

那么您可以:

  • 或者删除未使用的反向依赖以及 python3-yaml
  • 或通过 dpkg -r --force-depends python3-yaml 删除 python3-yaml 和 通过 pip
  • 重新安装
  • 或自行决定并在评论中分享结果

以下代码会有所帮助:

rm -rf /usr/lib/python3/dist-packages/yaml
rm -rf /usr/lib/python3/dist-packages/PyYAML-*
rm -rf /usr/lib/python3.8/site-packages/PyYAML-*
sudo -H pip3 install --ignore-installed PyYAML