When you are working with YAML module and you try to import the module without installing it on your system, you got ImportError: No module named yaml error. The error clearly says, we are using a module named YAML in our system which is not found. In this short article, we will discuss how we can solve ImportError No module named yaml error using various methods. Moreover, we will also discuss what does the error means and how we can interpret such errors in Python.
ImportError No module named yaml – Possible Solutions
The error ImportError No module named yaml clearly says we are using a module named YAML in our system that is not yet installed. To solve the error, we first need to install the YAML module on our system and then import it. Another reason for getting the error is because of the absence of the Pyyaml module on our system.

Now let us go through various methods to install the YAML module on our system.
Solution-1: Using Pip installation
One of the simplest methods to install any module on our system is to use the pip command. To install the module on your system, open the terminal and write the following commands.
# for mac and linux
pip install pyyaml
# using pip3 command
pip3 install pyyaml
# for mac and linux
python -m pip install pyyaml
# for windows
py -m pip install pyyaml
# for jupyter users
!pip install pyyaml
# for conda users
conda install pyyaml
Hopefully, this will help you to get rid of the error
Solution-2: Installing the module from the source file
If for some reason, the pip installation does not work on your system, you can then install the module directly from the source file.
Here are the steps which you need to follow in order to install the module.
- Download the pyYAMAL as a compressed file (link for downloading )
- In the next step, you can install the downloaded file on your system
Solution-3: Installing the module on Ubuntu
If you are a Linux user, then you can directly install the module on your system from the terminal. Open the terminal on the Ubuntu operating system and then type the following commands in order to install the module.
sudo apt install libyaml-dev
sudo yum -y install libyaml-devel
Once the installation will be complete, you will no more get the ImportError No module named yaml error.
Solution-4: Reinstalling the module
Sometimes, you might have a module on your system already installed but still get the ImportError No module named yaml error. If this is the case then you can uninstall the module first and then install it again.
You can use the following commands to uninstall the module.
pip3 uninstall pyyamal
If you are a Linux user, then you can use the following commands to remove the ymal module from your system.
sudo apt remove python3-yaml
sudo apt remove --auto-remove python3-yaml
sudo apt purge python3-yaml
sudo apt purge --auto-remove python3-yaml
Now, you can use any of the above given methods to install the module again on your system.
Understanding the ImportError No module named yaml error
As we discussed that the error usually occurs when the pyyamal module is not installed on the system. The error clearly says, there is an error in the importing of one module which is yaml. This error occurs becuase of not have pyYAML module on your system. You can solve the issue by installing the module on your system by using any of the methods that we have mentioned in this tutorial.
Frequently asked questions
How to install YAML on Windows?
You can use the pip command to install the YAML module on your system.
How to install YAML on Ubuntu?
If you are getting a module not found error, then you can use the sudo apt install libyaml-dev command to install the YAML module on your system.
How to uninstall the YAML module?
Use the following commands to uninstall or remove the module from your system.
sudo apt remove python3-yaml
Related Articles
- ValueError: Could Not Convert String to Float Solved
- ZeroDivisionError: division by zero in Python
- TypeError: Unsupported Operand Type(s) for -: ‘list’ and ‘list’
- ValueError: You Must Pass a Freq Argument as Current Index has None
- TypeError: ‘module’ object is not callable