CV2安装MediaPipe库后不起作用

发布于 2025-02-05 08:13:53 字数 2264 浏览 3 评论 0原文

我想使用Python制作手工跟踪程序,但是教程告诉我安装MediaPipe库,然后我安装了它。在此之前,使用CV2可以流式摄像机是可以的,但是在安装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) ```

我尝试再次安装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)

但是问题仍然存在。我该如何修复?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

病毒体 2025-02-12 08:13:53

我的情况与上述相同
您可以尝试一下:

pip install "opencv-python-headless<4.3"

此命令成功解决了这种情况

参考: https:// https://github.com/rudrabha /wav2lip/essess/387

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

毅然前行 2025-02-12 08:13:53

我也有类似的问题,我只安装了opencv-python。通过安装opencv-python-headless来解决该问题。


我的问题比这更复杂。实际上,OpenCV-Python已经安装在“ root”中,但是当我以其他用户(DEV)登录时,我会发现问题为OP。
我可以手动安装opencv-python-headlessopencv-contrib-python手动,然后系统将起作用。但是,如果我将它们安装在“ root”中,则我的sill存在相同的问题。

因此,我使用的最终解决方案是在我的用户环境中重新安装opencv-python

pip3 install-upgrade-upgrade -force-renstall opencv-python

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

滥情空心 2025-02-12 08:13:53

在任何版本(例如:4.6.0.66)中,当您安装任何2个包装中的任何2个软件包时:OpenCV-Contrib-Python,OpenCV-Python-Headless,OpenCV-Python,请确保它们具有相同的版本。我也遇到了同样的错误,我发现它们的版本不同。然后,同步更新解决了问题。

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.

静若繁花 2025-02-12 08:13:53

我使用以下命令来解决这样的问题。

PIP卸载OPENCV-CONTRIB-PYTHON

PIP安装OPENCV-CONTRIB-PYTHON

I fix such a problem using the following commands.

pip uninstall opencv-contrib-python

pip install opencv-contrib-python

顾挽 2025-02-12 08:13:53

以下解决方案

PIP安装“ OpenCv-Python-Headless&lt; 4.3”

已从源构建OpenCV时修复了以下错误!

导入CV2
Trackback(最近的最新电话):
文件“”,第1行,在
文件“ C:\ programData \ anaconda3 \ lib \ lib \ site-packages \ cv2_ init _。py”,第181行,in
Bootstrap()
文件“ C:\ programData \ anaconda3 \ lib \ lib \ site-packages \ cv2_ init _。py”,第153行,在Bootstrap中
本机_MODULE = ementlib.import_module(“ cv2”)
文件“ C:\ programData \ anaconda3 \ lib \ ementlib_ init> init _。py”,第127行,在import_module中
返回_bootstrap._gcd_import(name [level:],软件包,级别)
Importerror:导入CV2时DLL负载失败:找不到指定的模块。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文