The urllib is a python module for fetching and reading a URL. If you re getting the error no module named urllib then this tutorial is for you. In this entire tutorial you will know how to solve the error ModuleNotFound: no module named urllib error in easy way.
What is urllib ?
Python provide a module urllib that allows you to fetch and read the URL . URL is know as Uniform Resource Locator. The package provides you the following features:
- Requests for opening and reading a url.
- Parsing a URL
- Parsing a robots.txt file
The main application of the urllib to scrap content form the url.
But many developers get the no module named urllib error. In the next section you will know why you are getting this error and how to solve it.
Root Cause for no module named urllib
If you are importing the urllib module in pycharm and you are getting the red underline on the urllib word then you will get the ModuleNotFound: no module named urllib error.
import urllib
Output

The same error will come when you are importing the module on your terminal and command prompt.
The error is clearly saying that you have not installed urllib module on your system.
Solution for the error no module named urllib
The solution for the error no module urllib error is very simple. You have to install this module in your system. But to do you have to also check the version of the python.
If your system has python version 3.xx then use the pip3 command and if it is python2.xx then use the pip command.
To check the version of the python run the below command.
python --version

In my case the version of the python is 3.xx therefore I will use the pip3 command.
Use the below command to install the urllib python module.
pip3 install urllib

Once Installed, now if you import the package then you will not get the red underline and ModuleNotFound urllib error.
Conclusion
The urllib package is very useful for scrapping content from the webpages. If you are getting the modulenotfound error the the above method will solve this error.
Evene if you are finding the error then try to updgare the pip and again install the urllib. It will remove the error.
Leave a Reply