Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ModuleNotFoundError: No module named 'pyyaml'

Installing the package

I'm getting this error after trying all the following:

  1. pip3 install pyyaml
  2. Setup a virtualenv using pipenv and install it there
  3. sudo
  4. Install v5.1
  5. sudo python3 -m pip install pyyaml

The library in all cases seem to be properly installed.

$ pip3 show pyyaml
Name: PyYAML
Version: 5.4.1
Summary: YAML parser and emitter for Python
Home-page: https://pyyaml.org/
Author: Kirill Simonov
Author-email: [email protected]
License: MIT
Location: /usr/local/lib/python3.9/site-packages

In case of pipenv the location is Location: /Users/<username>/.local/share/virtualenvs/webwatch-zMzxdqeP/lib/python3.8/site-packages

Usage

In the application I simply import pyyaml and run it using either python3 <myapp>.py or doing the same thing using pipenv shell.

Result

On all cases ModuleNotFoundError: No module named 'pyyaml'

More info

$ ls -ls /usr/bin/python*
 0 lrwxr-xr-x  1 root  wheel     75 Jun 15  2020 /usr/bin/python -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
 0 lrwxr-xr-x  1 root  wheel     82 Jun 15  2020 /usr/bin/python-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
 0 lrwxr-xr-x  1 root  wheel     75 Jun 15  2020 /usr/bin/python2 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
 0 lrwxr-xr-x  1 root  wheel     75 Jun 15  2020 /usr/bin/python2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
 0 lrwxr-xr-x  1 root  wheel     82 Jun 15  2020 /usr/bin/python2.7-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
16 -rwxr-xr-x  1 root  wheel  31488 Aug 10  2020 /usr/bin/python3
 0 lrwxr-xr-x  1 root  wheel     76 Jun 15  2020 /usr/bin/pythonw -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7
 0 lrwxr-xr-x  1 root  wheel     76 Jun 15  2020 /usr/bin/pythonw2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7

References:

  1. https://github.com/yaml/pyyaml/issues/291
  2. Getting "ImportError: No Module named yaml" error
  3. https://github.com/ipython-contrib/jupyter_contrib_nbextensions/issues/590
like image 280
U_D Avatar asked Oct 21 '25 23:10

U_D


1 Answers

It's very simple and I'm surprised nobody has answered this yet: You just used the wrong name in the import statement.

The package is called PyYAML (see pip or the homepage), and so you indeed install it using:

pip install pyyaml

However, the Python package to import is called yaml.

So instead of:

import pyyaml

you should do:

import yaml

This can be seen in the examples in the tutorial.

Note that the three references you included in your question are about another error message, so they are not really relevant for this question.

like image 144
wovano Avatar answered Oct 24 '25 12:10

wovano



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!