Akshat Sharma
Akshat Sharma

Reputation: 73

ModuleNotFoundError: No module named 'yaml' error

I have a centos7 machine with python-2.7.5 installed as a default python. For my work, I need 3.x version of python on the same machine, so I have installed python-3.6.8 and created a soft link where /usr/bin/python point to /usr/bin/python3 with following command:

sudo ln -fs /usr/bin/python3 /usr/bin/python

Now, for a sample python script, let's say: test.py, I am getting ModuleNotFoundError: No module named 'yaml' error when I am trying to import yaml in it.

test.py script is as below:

#!/usr/bin/python3

"""
Sample python script to import yaml.
"""

import yaml

print("Hello! Could you please help me resolve this?")

And the error is as below:

[[email protected]]$python test.py
Traceback (most recent call last):
  File "test.py", line 6, in <module>
    import yaml
ModuleNotFoundError: No module named 'yaml'

I saw a couple of queries raised on stackoverflow and on github, like this, this and this, but do not see any response that has resolved this issue.

As suggested on the links above, I have installed pyyaml using below command:

sudo python3 -m pip install pyyaml and sudo pip3 install pyyaml but I am still continue to get ModuleNotFoundError error.

Could anyone please help me resolve this issue?

Thanks in advance,

Akshat Sharma

Upvotes: 6

Views: 19459

Answers (1)

Ayush Goel
Ayush Goel

Reputation: 11

Such issues occur when there are multiple distribution of python installed in your system.

Just run: pip3 list command and see whether you are able to see the package in the list. If not, you are not installing the PyYaml package at the correct location.

PS: also sometimes for normal user python is at different location and for sudo user, it is at different location. Check running the command without giving sudo.

Upvotes: 1

Related Questions