cv2 not work after install mediapipe library
Asked Answered
V

5

2

I want to make handtracker program using python but the tutorial tell me to install mediapipe library, then I installed it. Before that it's okay using cv2 to stream my camera, but after installing mediapipe, the cv2 doesn't work here the message :

>>>import cv2
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import cv2
  File "C:\Users\windows\AppData\Local\Programs\Python\Python39\lib\site-packages\cv2\__init__.py", line 181, in <module>
    bootstrap()
  File "C:\Users\windows\AppData\Local\Programs\Python\Python39\lib\site-packages\cv2\__init__.py", line 175, in bootstrap
    if __load_extra_py_code_for_module("cv2", submodule, DEBUG):
  File "C:\Users\windows\AppData\Local\Programs\Python\Python39\lib\site-packages\cv2\__init__.py", line 28, in __load_extra_py_code_for_module
    py_module = importlib.import_module(module_name)
  File "C:\Users\windows\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:\Users\windows\AppData\Local\Programs\Python\Python39\lib\site-packages\cv2\gapi\__init__.py", line 290, in <module>
    cv.gapi.wip.GStreamerPipeline = cv.gapi_wip_gst_GStreamerPipeline
AttributeError: partially initialized module 'cv2' has no attribute 'gapi_wip_gst_GStreamerPipeline' (most likely due to a circular import) ```

I tried to install opencv again but always get this message :

Requirement already satisfied: numpy>=1.19.3 in c:\users\windows\appdata\local\programs\python\python39\lib\site-packages (from opencv-python) (1.21.1)

but the problem still there. How do I fix it?

Edited : this is my pip list

C:\Users\windows>pip list
Package               Version
--------------------- --------
absl-py               1.1.0
attrs                 21.4.0
cycler                0.11.0
fonttools             4.33.3
kiwisolver            1.4.2
matplotlib            3.5.2
mediapipe             0.8.10
numpy                 1.21.1
opencv-contrib-python 4.6.0.66
opencv-python         4.5.3.56
packaging             21.3
Pillow                8.3.1
pip                   22.1.2
protobuf              4.21.1
pygame                2.1.2
pyparsing             3.0.9
python-dateutil       2.8.2
pyzbar                0.1.8
setuptools            56.0.0
six                   1.16.0
Vitreous answered 8/6, 2022 at 12:32 Comment(5)
Ensure you have only one version of OpenCV installed in your system/environmentAmphibology
perhaps mediapipe installed a conflicting package of OpenCV and now you've got multiple? probably. please list all the installed packages using pip. use pip list and find everything relating to opencv in that list. edit your question and add the information. if you see multiple opencv packages, uninstall all of them (using pip), then try reinstalling mediapipe.Wedding
@ChristophRackwitz There is opencv-contrib-python and opencv-python in there, I'll try itVitreous
I found the problem, when I installed mediapipe there is opencv-contrib-python, make the opencv-python twiceVitreous
I found a dirty fix: https://mcmap.net/q/82410/-cannot-import-opencv-because-of-circular-importBeria
J
5

I have the same situation like above you can try it:

pip install "opencv-python-headless<4.3"

This command has successfully resolved this situation

Reference:https://github.com/Rudrabha/Wav2Lip/issues/387

Jannjanna answered 15/6, 2022 at 2:51 Comment(0)
W
1

In any version(ex: 4.6.0.66), when you install any 2 of 3 packages: opencv-contrib-python, opencv-python-headless, opencv-python, make sure they have the same version. I also got the same error, I found out their versions are different. Then a synchronous update solved the problem.

Warbler answered 15/6, 2022 at 17:7 Comment(3)
installing those concurrently is a bad idea. only install one of them. they all contain the base modules (minus highgui, if headless).Wedding
yeah, you do not understand what I mean. I mean with one or two of those libraries (you can install according to your needs). But make sure they are the same version. As question problem above, he/she didn't install opencv-contrib-python, opencv-python same version so gave error, don't know if there is another error but I also had this problem and solved it's like that.Warbler
I do understand and am puzzled why you mistake that. it's still a bad idea to install those concurrently. that frequently leads to issues.Wedding
D
0

I have similar problem, and I only have opencv-python installed. The problem is solved by installing opencv-python-headless.


My problem is more complicate than that. Actually the opencv-python is already installed in "root", but when I login as another user (dev), I get the problem as OP. I can install opencv-python-headless or opencv-contrib-python manually, then the system will work. But if I install them in "root", I sill have the same problem.

So the final solution I use is to reinstall opencv-python in my user environment (dev):

pip3 install --upgrade --force-reinstall opencv-python

Determinable answered 15/6, 2022 at 21:48 Comment(0)
M
0

I fix such a problem using the following commands.

pip uninstall opencv-contrib-python

pip install opencv-contrib-python

Mood answered 21/6, 2022 at 14:11 Comment(0)
C
0

the following solution

pip install "opencv-python-headless<4.3"

fixed the error below when building OpenCV from source!

import cv2 Traceback (most recent call last): File "", line 1, in File "C:\ProgramData\Anaconda3\lib\site-packages\cv2_init_.py", line 181, in bootstrap() File "C:\ProgramData\Anaconda3\lib\site-packages\cv2_init_.py", line 153, in bootstrap native_module = importlib.import_module("cv2") File "C:\ProgramData\Anaconda3\lib\importlib_init_.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) ImportError: DLL load failed while importing cv2: The specified module could not be found.

Cowes answered 11/12, 2022 at 1:15 Comment(1)
Is that not just a copy of an existing answer? Or a comment to it? In both case, please avoid answering old question without making sure you have a new solution that was not given at the timeOcciput

© 2022 - 2025 — McMap. All rights reserved.