Cannot Import Mediapipe - Typeerror: 'Numpy. _Dtypemeta' Object Is Not Subscriptable

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

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?

3

4 Answers

I had this error while importing CV2. For this, use 1.20.0 version of numpy.

pip install numpy==1.20.0
2

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: 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.

I came across this problem when installing OpenCV(2) for PyAutoGUI. Specifically, I tried to use PyAutoGUI's locateOnScreen feature, and it told me that I needed OpenCV for the confidence parameter.

I installed OpenCV with pip install opencv-python, then tried importing PyAutoGUI again.

It threw an error that traced to OpenCV, similar to what the OP encountered:

TypeError: 'numpy._DTypeMeta' object is not subscriptable.

I had previously messed with numpy for machine learning, and I believe that was the issue; running pip install numpy==1.23.0 fixed it.

I solved the problem in 2 steps:

1. !pip install numpy --upgrade 
2. Restart the kernel 

Now, everything worked like a charm. Special thanks to gruvw.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Alexander Ross
Author

Alexander Ross

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.