How to resolve the modul enotfound rror?

207    Asked by diashrinidhi in Python , Asked on Aug 8, 2023

 I am receiving the modulenotdound error:nonmodule named ‘cv2’ when I attempted at importing the cv2 module in jupyter notebook.

Import cv2

Modulenotfounderror    Traceback (most recent call last)
In
—------------> 1 import cv2
Modulenotfounderror: no module named ‘cv2’

Answered by Diana Campbell

The error message is seen when you don’t install the opencv module in the system. Hence it is important to check whether the module is available or not. The error may occur when you don’t contain the module you attempted to import or you misspelled the module. Also using a wrong casing for the module while importing will push the module as not found error since the modules are different.


There are few ways to solve the problem. Ensure that imported modules are installed in the system. You can deploy the module ‘numpy’ in the code in the file named as “test.py” like the code mentioned below.

Import numpy as np
Arr = np.array ([1, 2, 3])
Print (arr)

When you attempt at running the code using python test.py and you see the error as:

      Modulenotfounderror: no module named “numpy”

Here the numpy module is not installed in your computer. The module can be installed in this way:

Python -m pip install numpy After installation, the earlier code will work well and you see the result in the terminal:

      [1, 2, 3].

Another solution is by ensuring that the modules are properly spelled. Few cases arise where the module is installed but while using it, it displays the error. Here, it may be that the module is misspelled. Have a look at this code given below: Import nompy as np

Arr = np.array ([1, 2, 3]0
Print (arr)
Here the module numpy is installed but while running the code, the error is seen:
ModuleNotFoundError : No module named “nompy”
The error is seen because of the misspelled numpy module as nompy. The problem can be solved by properly spelling the module.
The third solution is by ensuring that the modules are in proper casing
The issue can also lie that the module is in the improper casing.
Let’s have a look at the example:
Import Numpy as np
Arr = np.array ([1, 2, 3])
Print (arr)

Here there is numpy installed but executing this code will give the error as ModuleNotFoundError: No module named ‘Numpy’. Owing to casing problems, numpy and Numpy are separate modules. The error can be fixed by placing the module in the proper casing. The Python online training offered at JanBask Training gives you an experience like offline classes thereby saving the students from the tiring journey to travel to the physical locations. The course provides a total Python discipline’s preparation by touching on every core concept from basic to advanced thereby making you job ready to face the tough competitive market.



Your Answer

Interviews

Parent Categories