No module named ‘yaml‘

在使用如下命令时

python3 teacher_training.py

遇到了

Traceback (most recent call last):
  File "teacher_training.py", line 9, in 
    from AnomalyNet import AnomalyNet
  File "/home/lhy/liuwork/src/AnomalyNet.py", line 2, in 
    import pytorch_lightning as pl
  File "/home/lhy/.local/lib/python3.7/site-packages/pytorch_lightning/__init__.py", line 21, in 
    from pytorch_lightning.callbacks import Callback  # noqa: E402
  File "/home/lhy/.local/lib/python3.7/site-packages/pytorch_lightning/callbacks/__init__.py", line 21, in 
    from pytorch_lightning.callbacks.model_checkpoint import ModelCheckpoint
  File "/home/lhy/.local/lib/python3.7/site-packages/pytorch_lightning/callbacks/model_checkpoint.py", line 30, in 
    import yaml
ModuleNotFoundError: No module named 'yaml'

这样的问题。

然后查阅资料,说是要使用 pip 安装该包即可,但要注意的是安装的包名不是 yaml 而是 pyyaml,即 pip install pyyaml

然而使用后报错,

Requirement already satisfied: PyYAML in /home/ubuntu/anaconda3/lib/python3.7/site-packages (5.4.1)

查到某国外论坛(python - ImportError: No module named 'yaml' - Stack Overflowhttps://stackoverflow.com/questions/50868322/importerror-no-module-named-yaml)上的回答:Run which for each of python3 and pip3 to make sure they point to the same version, you can also try python3 -m pip install pyyaml 

于是尝试了python3 -m pip install pyyaml  ,成功解决了问题!

你可能感兴趣的:(报错,python,pytorch,深度学习,python)