解决报错cannot import name ‘_registerMatType‘ from ‘cv2.cv2‘

解决报错cannot import name ‘_registerMatType‘ from ‘cv2.cv2‘
使用yolox时系统运行报这个错误
解决报错cannot import name ‘_registerMatType‘ from ‘cv2.cv2‘_第1张图片

Traceback (most recent call last):
  File "tools/train.py", line 13, in <module>
    from yolox.core import Trainer, launch
  File "/user-data/YOLOX-main/yolox/__init__.py", line 4, in <module>
    from .utils import configure_module
  File "/user-data/YOLOX-main/yolox/utils/__init__.py", line 15, in <module>
    from .setup_env import *
  File "/user-data/YOLOX-main/yolox/utils/setup_env.py", line 9, in <module>
    import cv2
  File "/opt/conda/lib/python3.8/site-packages/cv2/__init__.py", line 9, in <module>
    from .cv2 import _registerMatType
ImportError: cannot import name '_registerMatType' from 'cv2.cv2' (/opt/conda/lib/python3.8/site-packages/cv2/cv2.cpython-38-x86_64-linux-gnu.so)

解决方法:
如果在notebook中执行以下命令

!pip uninstall opencv-python-headless
!pip install opencv-python-headless==4.1.2.30

如果在pycharm或者服务器上,执行以下命令

pip uninstall opencv-python-headless
pip install opencv-python-headless==4.1.2.30

如果有帮助请在评论区反馈
参考自stack overflow https://stackoverflow.com/questions/70537488/cannot-import-name-registermattype-from-cv2-cv2

你可能感兴趣的:(debug记录,linux,python,运维)