No module named ‘yaml‘ 解决办法

在尝试运行Python脚本时遇到了'yaml'模块未找到的错误。常规解决方案是使用`pip install yaml`,但该命令未能成功安装。实际上,正确安装yaml模块的命令是`pip install pyyaml`。执行此命令后,yaml模块成功安装,问题得到解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

错误现象:

Traceback (most recent call last):
  File "/home/pi/ble-uart-peripheral/uart_peripheral.py", line 16, in <module>
    import yaml
ModuleNotFoundError: No module named 'yaml'

一般来说,命令行使用以下命令就能解决问题:

pip install yaml

但是,很遗憾,结果提示如下:

pi@pi:~/HeatMap $ pip install yaml
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting yaml
  Could not find a version that satisfies the requirement yaml (from versions: )
No matching distribution found for yaml

其实正确的命令行内容应该是如下所示:

pip install pyyaml

结果显示成功

pi@pi:~/HeatMap $ pip install pyyaml
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting pyyaml
  Downloading https://files.pythonhosted.org/packages/a0/a4/d63f2d7597e1a4b55aa3b4d6c5b029991d3b824b5bd331af8d4ab1ed687d/PyYAML-5.4.1.tar.gz (175kB)
    100% |████████████████████████████████| 184kB 481kB/s 
  Installing build dependencies ... done
Building wheels for collected packages: pyyaml
  Running setup.py bdist_wheel for pyyaml ... done
  Stored in directory: /home/pi/.cache/pip/wheels/2a/d4/92/cf299bdf4162957ca8126b46e913e29f76a4f17ca762c45028
Successfully built pyyaml
Installing collected packages: pyyaml
Successfully installed pyyaml-5.4.1
pi@pi:~/HeatMap $ 

评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

村北头的码农

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

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

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

打赏作者

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

抵扣说明:

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

余额充值