安装yaml报错:ERROR: Cannot uninstall 'PyYAML'.

1,858 阅读2分钟

携手创作,共同成长!这是我参与「掘金日新计划 · 8 月更文挑战」的第4天,点击查看活动详情

一、错误原因分析

1、开始安装 我是一开始安装yaml,使用命令:

pip install yaml

正确安装,且可以在命令行下正确导入,然后在执行程序的时候又报错:AttributeError: module 'yaml' has no attribute 'FullLoader'然后我就查看了一下我安装的yaml的版本:

pip show yaml   # 显示是3.12版本,版本太老

2、错误探索1 网上查看教程,说是要更新yaml的版本到5.2,更新的方式如下:

pip install -U PyYAML

更新的过程中又报错:

ERROR: 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.

然后又继续查找如何解决这个问题,大部分给出的解决方案是:把site-packages下的yaml文件全部删除干净,你猜怎么着,LZ全部删除了,结果安装的时候还是这个BY,你气不气,无奈呀!

ERROR: 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.

3、错误探索2

无奈,我只能去PyPi网站上去下载轮子了,然后直接安装了:

  • PyYAML-5.2-cp27-cp27m-win_amd64.whl
  • PyYAML-5.2-cp27-cp27m-win32.whl

然后直接安装轮子:

pip install PyYAML-5.2-cp27-cp27m-win_amd64.whl
# 然后说是平台不支持,我一看是amd可能不支持,于是我又试了一下32的

pip install PyYAML-5.2-cp27-cp27m-win32.whl
# 同样是平台不支持,无语至极

看来是探索是失败的,另辟蹊径吧!

二、最终错误解决方式

使用下面的安装方式解决(参数的具体含义可以使用pip install -h查看):

# 亲测可用
pip install --ignore-installed PyYAML

还有一种,这个我没有测试,你可以试一下(你可以自己尝试一下,有没有问题!):

pip install  --force-reinstall PyYAML

pip install docker-py --ignore-installed PyYAML

参考: 1、github.com/pypa/pip/is… 2、stackoverflow.com/questions/4…