How To Solve ModuleNotFoundError: No module named in Python
In this article, I am going to show you what are the reasons for this error and how to solve it.
1. The name of the module is incorrect
The first reason of this error is the name of the module is incorrect, so you have to check out the module name that you had imported.
For example, let's try to import Os module with double s and see what will happen:
>>> import oss Traceback (most recent call last): File "<stdin>", line 1, in <module> ModuleNotFoundError: No module named 'oss'
as you can see, we got No module named 'oss'.
2. The path of the module is incorrect
The Second reason is Probably you would want to import a module file, but this module is not in the same directory.
core.py folder_1 ---module.py
now, we want to import module.py
import module.py #incorrect
ModuleNotFoundError: No module named 'module'
import folder_1.module.py #correct
...Program finished with exit code 0
as you can see the problem has been solved
3. The Library not installed
Also, you can get the issue if you are trying to import a module of a library which not installed in your virtual environment. So before importing a library's module, you need to install it with the pip command.
For example, let's try to import the Beautifulsoup4 library that's not installed in my virtual environment.
>>> from bs4 import BeautifulSoup Traceback (most recent call last): File "<stdin>", line 1, in <module> ModuleNotFoundError: No module named 'bs4'
now, let's install the library and try to re-import it
pip install beautifulsoup4 Collecting beautifulsoup4 Using cached https://files.pythonhosted.org/packages/d1/41/e6495bd7d3781cee623ce23ea6ac73282a373088fcd0ddc809a047b18eae/beautifulsoup4-4.9.3-py3-none-any.whl Requirement already satisfied: soupsieve>1.2; python_version >= "3.0" in /home/py/Desktop/seo_pro/seo_env/lib/python3.6/site-packages (from beautifulsoup4) (1.9.5) Installing collected packages: beautifulsoup4 Successfully installed beautifulsoup4-4.9.3
>>> from bs4 import BeautifulSoup >>>
as you can see, after installing the library, the problem is solved.
English today is not an art to be mastered it's just a tool to use to get a result