【Python】No module named ‘yaml‘ 解决办法

一、yaml包的介绍

yaml是一种文件格式,跟json一样通常被用作配置文件,但远比 JSON 格式方便!使用json作为配置文件的朋友会发现,在json中写注释要通过增加键值对的形式来,但是yaml格式就非常的友好!

建议使用yaml来写配置文件,如下为yaml格式的示例:

在这里插入图片描述

二、使用报错及安装成功

我训练模型的时候,出现了错误,如下所示:

Traceback (most recent call last):
  File "train.py", line 24, in <module>
    import yaml
ModuleNotFoundError: No module named 'yaml'

在这里插入图片描述

ModuleNotFoundError: No module named 'yaml'

说明我们的环境中缺乏yaml包,尝试安装:

pip install yaml

但是报错:

Looking in indexes: http://mirrors.aliyun.com/pypi/simple
ERROR: Could not find a version that satisfies the requirement yaml (from versions: none)
ERROR: No matching distribution found for yaml

在这里插入图片描述
其实正确的命令行内容应该是如下所示:

pip install pyyaml

这样就成功了!如下所示:

Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting pyyaml
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c8/6b/6600ac24725c7388255b2f5add93f91e58a5d7efaf4af244fdbcc11a541b/PyYAML-6.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (736 kB)
     |████████████████████████████████| 736 kB 1.1 MB/s 
Installing collected packages: pyyaml
Successfully installed pyyaml-6.0.1
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

在这里插入图片描述

  • 23
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

旅途中的宽~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值