I have installed OpenCV on windows
When I try import cv2 in a Python program, I get the following message:
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'
CodePudding user response:
Make sure opencv-python package is installed on the environment that you use.
You can use pip freeze
to see installed packages, and if it is not listed you can install opencv wrapper for python with:
pip install opencv-python
CodePudding user response:
There could be a number of issues causing this error. What I would do is this:
Make sure your project is not open in a python venv. Go to the terminal and type:
pip3 install opencv-python
I am using pip3 because I am installing this for python 3. The version is something you have to check as well. If you are not sure which version of pip is used for what version of python, simply type in your terminal:
pip3 --version
This should install opencv under:
C:\Users\{your_username}\AppData\Local\Programs\Python\Python{version}\Lib\site-packages\cv2
Once you confirm the existence of the package, create a new python file on your Desktop or something and simply type:
import cv2
print(cv2)
Then run this using python3 (because as you remember, we used pip3 to install the module).
If the first line doesn't raise an exception then you have successfully imported cv2. The second line will print the module's location if it is of any interest.