pyyaml: ModuleNotFoundError: No module named 'yaml'

Hi,

I have updated to the newest version 5.1 but yaml module is not available:

yaml version: 5.1 python version: Python 3.7.1 OS version: macOS Sierra 10.13.6

Any idea? Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 21 (3 by maintainers)

Commits related to this issue

Most upvoted comments

This is a common issue with Macs that has nothing to do with pyyaml- need to read up on system Python vs user Python and make sure you’re using the right tools for the right Python version.

I had the same issue, pyyaml showing as installed but throwing the “no module” error. This fix worked for me 😃
sudo easy_install pip sudo python -m pip install pyyaml

It’s not just a Mac issue, but it’s extremely common on Macs (thanks Homebrew Python!), and has nothing to do with pyyaml. The issue is mismatched Python tools, where different tools are targeting different site-packages directories (eg, your easy_install probably targets a different Python environment than python does). Go look at any well-used Python library’s issue list, and you’ll find people asking this same question. There’s nothing the projects can do to improve the situation, so the issues get closed.

So I did some digging following what @nitzmahone said. This is how I fixed mine [There’s obviously variations to this, the deal is to make sure the install location is included in your sys.path]:

  1. Find out where pyyaml is currently installed. If you run pip install pyyaml, and it tells you where it’s currently installed. E.g. for me it was /opt/anaconda3/lib/python3.7/site-packages, for OP it seems to be /Users/marcos/.virtualenvs/pyinstamation/lib/python3.6/site-packages
  2. Add export PYTHONPATH='wherever pyyaml is currently installed' to your .bash_profile (I’m on mac)
  3. Restart your terminal
  4. Optional, confirm that path is now part of your sys.path through python repl for example
  5. Retry whatever you were trying to do again.

@hafbau Thank you. this worked

So I did some digging following what @nitzmahone said. This is how I fixed mine [There’s obviously variations to this, the deal is to make sure the install location is included in your sys.path]:

  1. Find out where pyyaml is currently installed. If you run pip install pyyaml, and it tells you where it’s currently installed. E.g. for me it was /opt/anaconda3/lib/python3.7/site-packages, for OP it seems to be /Users/marcos/.virtualenvs/pyinstamation/lib/python3.6/site-packages

  2. Add export PYTHONPATH='wherever pyyaml is currently installed' to your .bash_profile (I’m on mac)

  3. Restart your terminal

  4. Optional, confirm that path is now part of your sys.path through python repl for example

  5. Retry whatever you were trying to do again.

Hi @nitzmahone , is it just macs? As I’m getting this error on Ubuntu 16 when trying to run a cmake file. I also ran python3 -m pip install pyyaml to install it but it said the requirement has already been satisfied.

Any advice would be appreciated! Thanks for your help so far!

sudo pip3 install pyyaml worked for me on the Raspberry Pi