pythonpython-3.xnumpytypeerrormediapipe

Cannot import mediapipe - TypeError: 'numpy._DTypeMeta' object is not subscriptable


The install is successful. I receive this error when trying to import.

TypeError: 'numpy._DTypeMeta' object is not subscriptable

enter image description here

I have tried higher and lower versions of numpy (1.22.0,1.23.0,1.24.0,1.25.0,1.25.2). I installed mediapipe via pypi as well as a downloaded whl ( mediapipe-0.10.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl) from pypi

Versions

numpy                        1.21.5
mediapipe                    0.10.3

Python 3.10.6

These questions are similar but not the answer.

Importing xarray raises not subscriptable issue

Cannot import mediapipe in Jupyter notebook

How to prevent error message when importing import cv2?


Solution

  • Updating numpy to 1.23 works. I was not restarting the kernel after installing versions of numpy. With notebook-scoped libraries, use dbutils.library.restartPython(). If you are using cluster-scoped libraries, then be sure to restart your cluster.

    There's an issue about this that's documented on the OpenCV repo here: https://github.com/opencv/opencv/issues/23822 In short, it imported successfully with most numpy>=1.22.0 versions. Just be careful, if you use some of the most recent library versions, like numpy>=1.25.0, you start running into other compatibility issues.