22

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
antong
  • 387
  • 1
  • 2
  • 11

7 Answers7

44

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

sudo pip install pyyaml
Wtower
  • 18,848
  • 11
  • 103
  • 80
bigdata2
  • 999
  • 1
  • 11
  • 17
  • ansible (2.2.0) cffi (1.7.0) cryptography (1.4) Django (1.9.6) enum34 (1.1.6) Flask (0.10.1) httplib2 (0.9.2) idna (2.1) ipaddress (1.0.16) itsdangerous (0.24) Jinja2 (2.8) MarkupSafe (0.23) paramiko (2.0.1) pip (1.5.6) pyasn1 (0.1.9) pycparser (2.14) pycrypto (2.6.1) PyYAML (3.11) setuptools (23.1.0) six (1.10.0) vboxapi (1.0) Werkzeug (0.11.2) wsgiref (0.1.2) yolk3k (0.9) (from pip list) – antong Jul 01 '16 at 16:42
  • Then the installation directory of yaml module is likely not in sys.path You can check it by importing sys and printing sys.path – bigdata2 Jul 01 '16 at 17:10
9

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.

r17n
  • 225
  • 3
  • 4
4

For python 3.6 you can install it with

pip3 install pyyaml

if there is a problem in importing, do

pip3 uninstall pyyaml

and then install it again:

pip3 install pyyaml
Ali
  • 387
  • 4
  • 11
3

@bigdata2's answer is correct but it might also happen that there's a conflict with python 3. So, check pip version (pip --version) and if it outputs python 3 then:

sudo python -m pip install pyyaml

So it gets installed for the same version as python.

FranMowinckel
  • 4,233
  • 1
  • 30
  • 26
1

I had this problem because I installed it with

sudo pip install pyyaml --upgrade

instead of

sudo -H pip install pyyaml --upgrade

Uninstalling and re-installing pyyaml fixed the problem for me.

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
0

This should work:

sudo pip install pyyaml    
Tushar
  • 528
  • 4
  • 20
0

Try this

pip install ruamel.yaml
pergy
  • 5,285
  • 1
  • 22
  • 36