Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "ImportError: No Module named yaml" error

Tags:

Computer: MacBook Pro mid 2012, running El Capitan 10.11.4

Python version 2.7.10

I've been trying to install ansible from source, and I've run these two commands (following the steps on ansibles documentation):

git clone git://github.com/ansible/ansible.git --recursive cd ./ansible 

and then ran this

source ./hacking/env-setup 

I've also already installed these packages

sudo pip install paramiko PyYAML Jinja2 httplib2 six 

However, if I try and run ansible by typing it in the terminal, I get the following error.

Traceback (most recent call last): File "/Users/[myusr]/rock/ansible/bin/ansible", line 81, in <module> from ansible.cli.adhoc import AdHocCLI as mycli File "/Users/[myusr]/rock/ansible/lib/ansible/cli/__init__.py", line 27, in <module> import yaml ImportError: No module named yaml 

What should be done here?

like image 831
antong Avatar asked Jun 30 '16 19:06

antong


People also ask

How do I read a YAML file in Python?

We can read the YAML file using the PyYAML module's yaml. load() function. This function parse and converts a YAML object to a Python dictionary ( dict object). This process is known as Deserializing YAML into a Python.

What is pyyaml Python?

PyYAML is a YAML parser and emitter for Python. PyYAML features a complete YAML 1.1 parser, Unicode support, pickle support, capable extension API, and sensible error messages. PyYAML supports standard YAML tags and provides Python-specific tags that allow to represent an arbitrary Python object.


2 Answers

Do you have yaml module installed? If not, try installing yaml using the following command:

sudo pip install pyyaml 
like image 93
bigdata2 Avatar answered Sep 20 '22 14:09

bigdata2


Had the same issue. Got past it using @FranMowinckel's answer.

First I typed:

pip --version  

it outputted python 3. But, when I tried:

sudo python -m pip install pyyaml 

I got an error saying:

Error: No module named pip

So, finally running:

sudo easy_install pip 

everything worked fine. Go back and run:

sudo python -m pip install pyyaml 

(you may have to run this with all the other modules as well) Now you should finally be able to run your initial command which failed.

like image 36
r17n Avatar answered Sep 20 '22 14:09

r17n