简体   繁体   English

安装 mediapipe 库后 cv2 不工作

[英]cv2 not work after install mediapipe library

I want to make handtracker program using python but the tutorial tell me to install mediapipe library, then I installed it.我想使用 python 制作 handtracker 程序,但教程告诉我安装 mediapipe 库,然后我安装了它。 Before that it's okay using cv2 to stream my camera, but after installing mediapipe, the cv2 doesn't work here the message:在此之前可以使用 cv2 到 stream 我的相机,但是在安装 mediapipe 之后,cv2 在这里不起作用消息:

>>>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:我尝试再次安装 opencv 但总是收到此消息:

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编辑:这是我的 pip 列表

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

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参考: https ://github.com/Rudrabha/Wav2Lip/issues/387

In any version(ex: 4.6.0.66), when you installe 3 packages: opencv-contrib-python, opencv-python-headless, opencv-python, make sure they have the same version.在任何版本(例如:4.6.0.66)中,当您安装 3 个包时:opencv-contrib-python、opencv-python-headless、opencv-python,请确保它们具有相同的版本。 I also got the error, I found out their versions are different.我也得到了错误,我发现他们的版本不同。 Then a synchronous update solved the problem.然后同步更新解决了这个问题。

I have similar problem, and I only have opencv-python installed.我有类似的问题,我只安装了opencv-python The problem is solved by installing opencv-python-headless .通过安装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.实际上 opencv-python 已经安装在“root”中,但是当我作为另一个用户(dev)登录时,我得到了 OP 的问题。 I can install opencv-python-headless or opencv-contrib-python manually, then the system will work.我可以手动安装opencv-python-headlessopencv-contrib-python ,然后系统就可以工作了。 But if I install them in "root", I sill have the same problem.但是如果我将它们安装在“root”中,我仍然会遇到同样的问题。

So the final solution I use is to reinstall opencv-python in my user environment (dev):所以我使用的最终解决方案是在我的用户环境(dev)中重新安装opencv-python

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

I fix such a problem using the following commands.我使用以下命令解决了这样的问题。

pip uninstall opencv-contrib-python pip 卸载 opencv-contrib-python

pip install opencv-contrib-python点安装 opencv-contrib-python

the following solution以下解决方案

pip install "opencv-python-headless<4.3" pip 安装“opencv-python-headless<4.3”

fixed the error below when building OpenCV from source!修复了从源代码构建 OpenCV 时出现的以下错误!

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.导入cv2 Traceback(最近调用最后一次):文件“”,第 1 行,在文件“C:\ :\ProgramData\Anaconda3\lib\site-packages\ cv2_init_.py ",第 153 行,在 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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM