一.需求
其他库要求pyyaml版本大于5.0,但更新pyyaml时总是报错或者安装后仍为原先版本。
二.方法集锦
(此处都是尝试但未能正确解决的方式,可以直接看三)
-
先卸载pyyaml再安装
pip uninstall PyYaml
但是会产生如下相同报错{卸载步骤}ERROR: Cannot uninstall 'PyYAML'. It is a distutils installed project and thus we cannot accurately determine which files belong to it whic h would lead to only a partial uninstall.
-
使用忽略已安装 命令:
pip install --ignore-installed PyYAML==5.1
此种情况能正常运行,但是安装完毕后发现是原版本
PS E:\python\ChatGLM> pip install --ignore-installed PyYAML==5.1 Using cached PyYAML-5.1-cp37-cp37m-win_amd64.whl (215 kB) Installing collected packages: PyYAML Successfully installed PyYAML-3.13 # 而不是5.1!!
-
使用镜像源下载
无效,得到报错同1
三.最终解决
检查1的报错,发现是存在多个不同的yaml包导致卸载不明确
因此首先需要找到yaml的文件夹
pip show pyyaml
返回结果 location行 即为yaml包所在文件夹
找到文件夹,删除其下 全部yaml库文件夹 和 yaml.egg-info[删的时候发现确实有多个但是没找到3.13]
之后再重新运行忽略已安装版本的命令
pip install --ignore-installed PyYAML==5.1
完成yaml更新
>>> pip install --ignore-installed PyYAML==5.1 Collecting PyYAML==5.1 Using cached PyYAML-5.1-cp37-cp37m-win_amd64.whl (215 kB) Installing collected packages: PyYAML Successfully installed PyYAML-5.1