0

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: xi@resolvent.net
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
wovano
  • 4,543
  • 5
  • 22
  • 49
U_D
  • 711
  • 1
  • 10
  • 18

3 Answers3

2

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.

wovano
  • 4,543
  • 5
  • 22
  • 49
0

Have tried an installation by specifying python3

python3 -m pip install pyyaml

or with sudoers permission

Suyog Shimpi
  • 706
  • 1
  • 8
  • 16
-1

same problem: since I installed python jupyter .. with miniconda3, I tried with conda install pyyaml and that's ok now.