2

I am using CentOS 6.4 with Python 2.6.6 to run Ansible 2.3.0. But when I go into my python virtual env which has python 3.4.1 and run "ansible --version" I get the following error:

Traceback (most recent call last):
File "/home/namaaror/Desktop/githubansible/bin/ansible", line 80, in <module>
from ansible.cli.adhoc import AdHocCLI as mycli
File "/home/namanarora/Desktop/github/ansible/lib/cli/__init__.py", line 28, in <module>
import yaml
ImportError: No module named 'yaml'

I have even tried installing pyyaml by reffering ImportError: No Module named yaml | Ansible but the error still persists. Is it somewhat related to yaml installation directory and sys.path?

Community
  • 1
  • 1
Naman
  • 29
  • 4

2 Answers2

1

After you activate a virtualenv (via ansible or not) you should not have to use sudo to install something with pip as the whole virtualenv and all its directories are owned by you.

In fact if you use sudo you will probably not use the virtualenv's pip:

$ mktmpenv
Using real prefix '/opt/python/2.7'
New python executable in /home/venv/tmp-ef9b4ef621d87221/bin/python
Installing setuptools, pip, wheel...done.
This is a temporary environment. It will be deleted when you run 'deactivate'.
(tmp-ef9b4ef621d87221) $ which pip
/home/venv/tmp-ef9b4ef621d87221/bin/pip
(tmp-ef9b4ef621d87221) $ sudo which pip
[sudo] password for root: 
/usr/local/bin/pip

(the answer might be the same, depending on your login scripts and root's PATH). So you should not use sudo pip install when installing things after activating the virtualenv, just use

pip install ....
Anthon
  • 69,918
  • 32
  • 186
  • 246
0

Check out your python3 dist-packages directories /usr/local/lib/pythonX.XX/dist-packages to see if pyyaml is installed there.

If they aren't there, you can install them with sudo apt-get install python3-yaml (you might need python3-setuptools and python3-wheel as well)

Nelson
  • 414
  • 3
  • 17