The modulenotfounderror: no module named ‘cv2’ happened when the opencv-python isn’t installed before being imported or is installed in the wrong environment. Thus, it throws the Python error “ModuleNotFoundError: No module called ‘cv2′”. Run the pip install opencv-python command to install the module in order to resolve the issue.
No Module Named ‘cv2’ Occurs For Multiple Reasons
- Not having the opencv-python package installed by running pip install opencv-python.
- Installing the package in a different Python version than the one you’re using.
- Installing the package globally and not in your virtual environment.
- Your IDE running an incorrect version of Python.
- Naming your module cv2.py which would shadow the official module.
- Declaring a variable named cv2 which would shadow the imported variable.
How To Fix No Module Named cv2?

To fix this issue, first open your terminal in your project’s root directory and after that install the opencv-python module.
Here’s the different syntax to fix the issue about No Module Named cv2 in different python versions:
1. In a virtual environment or using python 2.
pip install opencv-python2. For python 3 (could also be pip3.10 depending on your version).
pip3 install opencv-python3. If you get permissions error
sudo pip3 install opencv-python
pip install opencv-python --user4. If you don’t have pip in your PATH environment variable.
python -m pip install opencv-python5. For python 3 (could also be pip3.10 depending on your version).
python3 -m pip install opencv-python6. Using py alias (Windows).
py -m pip install opencv-python7. For Anaconda
conda install -c conda-forge opencv8. For Jupyter Notebook
!pip install opencv-pythonAfter you install the opencv-python module, try importing it like this:
import cv2
print(cv2.__version__)Conclusion
We have completely discussed about ModuleNotFoundError: No Module Named ‘cv2’ and how to solve this issue. The modulenotfounderror: no module named ‘cv2’ happened when the opencv-python isn’t installed before being imported or is installed in the wrong environment. Thus, it throws the Python error “ModuleNotFoundError: No module called ‘cv2′”.
Recommendation
By the way, if you encounter an error about importing libraries. I have here the list of articles made to solve your problem on how to fix errors in libraries.
- ModuleNotFoundError: No Module Named Pycocotools
- ERROR: Error:0308010c:Digital Envelope Routines::Unsupported
- Only Size-1 Arrays Can Be Converted To Python Scalars
- AttributeError: Module TensorFlow Has No Attribute Contrib
- ‘Smote’ Object Has No Attribute ‘fit_sample
- NameError: Name plot_cases_simple Is Not Defined
- AttributeError: HTMLParser Object Has No Attribute Unescape
Inquiries
By the way, If you have any questions or suggestions about this article, please feel free to comment below.
Frequently Asked Questions
What is Python ModuleNotFoundError and what causes it?
ModuleNotFoundError (a subclass of ImportError) is raised when Python cannot find the module you tried to import. Common causes: the package isn’t installed (pip install missing), wrong virtual environment activated, typo in module name, or Python can’t find your local module on the import path. The error message names exactly which module is missing.
How do I fix ‘ModuleNotFoundError: No module named X’?
Run pip install X first. If that succeeds but you still get the error, check which Python you’re using (which python OR python –version) vs which pip (which pip OR pip –version), they must match. Common gotcha: pip points to system Python 3.9 but you’re running python3.11 in a venv. Inside the venv, use python -m pip install X to be sure pip matches the active Python.
Why does my code work in one environment but not another?
Different Python versions or different installed packages. To diagnose: pip freeze > requirements.txt on the working environment, then pip install -r requirements.txt on the broken one. Use virtualenv (python -m venv venv) or conda for every project to avoid system-wide package collisions.
Is ModuleNotFoundError the same as ImportError?
ModuleNotFoundError is a subclass of ImportError added in Python 3.6. It specifically means ‘no such module exists.’ Plain ImportError covers a wider set: module exists but a name inside it can’t be imported (e.g. ‘cannot import name X from Y’). except ImportError catches both; except ModuleNotFoundError catches only the missing-module case.
Where can I find more ModuleNotFoundError fixes?
Browse the ModuleNotFoundError reference hub for 198+ specific module fixes (TensorFlow, Flask, Django, pandas, numpy, etc.). For related issues see ImportError. For broader Python setup see Python Tutorial hub.

Thank You for sharing such an amazing blog!
Thank You for sharing such an amazing blog!
Very good!
I liked…….
Thank You for sharing such an amazing blog!
Very good!
.
Thank You for sharing such an amazing blog!
.
I am worndering to find such an informative content.. GTU 12
I really enjoyed exploring your site. good resource. continu..
GTU
very nice website article
GTU
fantastic article
GTU
Really nice and very informative. GTU
I am worndering to find such an informative content GTU
nice website article thanks for the informations
thank you for your efforts
very nice website article
GTU
I really enjoyed exploring your site. good resource. continu..
GTU
nice website article thanks for the informations
I really enjoyed exploring your site. good resource. continu..
>
Thanks for sharing very good information…
GTU
Great work! I appreciate your work GTU
This article is interesting. Thanks!
GTU
Merci beaucoup pour ce sujet