0

I was installed all the opencv modules:

(venv) D:\#6>pip install opencv-python-headless
Collecting opencv-python-headless
  Downloading opencv_python_headless-4.5.5.64-cp36-abi3-win_amd64.whl (35.3 MB)
     ---------------------------------------- 35.3/35.3 MB 9.2 MB/s eta 0:00:00
Requirement already satisfied: numpy>=1.17.3 in d:\venv\lib\site-packages (from opencv-python-headless) (1.22.4)
Installing collected packages: opencv-python-headless
Successfully installed opencv-python-headless-4.5.5.64
(venv) D:\#6>pip install opencv-contrib-python-headless
Collecting opencv-contrib-python-headless
  Downloading opencv_contrib_python_headless-4.5.5.64-cp36-abi3-win_amd64.whl (42.1 MB)
     ---------------------------------------- 42.1/42.1 MB 7.5 MB/s eta 0:00:00
Requirement already satisfied: numpy>=1.14.5 in d:\venv\lib\site-packages (from opencv-contrib-python-headless) (1.22.4)
Installing collected packages: opencv-contrib-python-headless
Successfully installed opencv-contrib-python-headless-4.5.5.64
(venv) D:\#6>pip install opencv-python
Requirement already satisfied: opencv-python in d:\venv\lib\site-packages (4.5.5.64)
Requirement already satisfied: numpy>=1.14.5 in d:\venv\lib\site-packages (from opencv-python) (1.22.4)
(venv) D:\#6>pip install opencv-contrib-python
Requirement already satisfied: opencv-contrib-python in d:\venv\lib\site-packages (4.5.5.64)
Requirement already satisfied: numpy>=1.17.3 in d:\venv\lib\site-packages (from opencv-contrib-python) (1.22.4)

My pip list:

Package                        Version
------------------------------ --------
numpy                          1.22.4
opencv-contrib-python          4.5.5.64
opencv-contrib-python-headless 4.5.5.64
opencv-python                  4.5.5.64
opencv-python-headless         4.5.5.64
Pillow                         9.1.1
pip                            22.1.2
PyYAML                         6.0
setuptools                     58.1.0

When I import cv2 to the code, it show me an error:

(venv) D:\#6>py
Python 3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'

So how can I fix this? Help me please.
Thank you =)

2
  • 1
    What does the rest of the traceback say? Do you have several python versions and which version does pip maintain on your system? Commented Jun 7, 2022 at 4:57
  • I forgot to post that. changed now. Commented Jun 7, 2022 at 5:10

2 Answers 2

2

You installed conflicting modules. Remove everything, install one of them.

opencv-contrib-python          4.5.5.64
opencv-contrib-python-headless 4.5.5.64
opencv-python                  4.5.5.64
opencv-python-headless         4.5.5.64

You must never have more than one of them at any time.

All of them contain the basic OpenCV modules.

The -headless variants omit highgui.

The -contrib variants add contrib modules but are not addons. They are complete packages that contain all the basic modules.

Sign up to request clarification or add additional context in comments.

2 Comments

While this looks like a problem, shouldn't the import still work – albeit picking one arbitrarily?
opencv package variants are known to conflict. this can appear as missing things in the cv2 import, or the entire thing can't be imported. -- this OP probably has multiple pythons, judging by their own answer. -- either way, multiple imports are an issue and need to be fixed, regardless of whether or not that directly caused the issue reported by OP.
0

Use "python.exe -m pip install <module>" instead of "pip install <module>"

1 Comment

that can't have made a difference unless you have multiple pythons and got confused by which you're currently using.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.