If you are certain that you have installed CV2, but you run into "no module named cv2" when running Python, that means CV2 was installed to a different Python version from the one you are running.
You probably have multiple Python versions installed on different folders and your PATH is probably in disarray as well. Different IDEs and editors have different ways to select your Python versions.
If installing OpenCV again doesn't solve it, you can do a clean Python installation. I can't provide a step-by-step guide, but here is the general plan:
- Uninstall all instances of Python
- Remove Python from your path. Delete any reference in the PATH to Python
- Proceed with caution: Delete any remaining files for user-installed Python, not system Python. For Windows, it is
C:\Users\%USERNAME%\AppData\Local\Programs\Python. For Mac, the system Python is at
/usr/bin/pythonso you should avoid touch this. Extra installations of Python are usually at
/usr/local/bin/python` and these are safe to remove.
After this, install any Python version you wish to use. However, I recommend looking into pyenv, virtualenvs and the likes so you can use a specific Python install for a project and minimize the chance of conflicting modules and versions.
example.py
may use a different Python version than running viapython example.py
superuser.com/questions/433897/…