You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
module 'cv2.dnn' has no attribute 'DictValue' #884
Hi! I've come to an issue with the latest opencv (4.8.0.76)
I think you've changed functionality which is now not backward compatible
Full traceback:
import cv2
File "/usr/local/lib/python3.8/dist-packages/cv2/__init__.py", line 181, in <module>
bootstrap()
File "/usr/local/lib/python3.8/dist-packages/cv2/__init__.py", line 175, in bootstrap
if __load_extra_py_code_for_module("cv2", submodule, DEBUG):
File "/usr/local/lib/python3.8/dist-packages/cv2/__init__.py", line 28, in __load_extra_py_code_for_module
py_module = importlib.import_module(module_name)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/usr/local/lib/python3.8/dist-packages/cv2/typing/__init__.py", line 169, in <module>
LayerId = cv2.dnn.DictValue
AttributeError: module 'cv2.dnn' has no attribute 'DictValue'```
Python=3.7
Reacted by Kyle Sargent, Maxim Bonnaerens, Sergii Penner, Abdullah Al Rafi, Qingmao Wei, CosmicMuffin, Chen Cui, Hugues de Saxcé, Seppo Enarvi, 呂逸瑋 and 11 more
Can confirm that this issue happens in the latest release by simply running import cv2.
The previous version opencv-python==4.8.0.74 works fine,.
Maybe it has something to do with the way import work?
Reacted by Elena, kenneth, catidog, Abdullah Al Rafi, Hikaru Watanabe, CosmicMuffin, Camilo Núñez Fernández, Patrick von Platen, liuxiaolong98, Seppo Enarvi and 26 more
Reacted by Kannan K, catidog, Abdullah Al Rafi, alexanderkomarovincode3, Henrique Mendonça, Eliza and black and Yunze Man
I faced this issue while using YOLOV8. For my case, the docker container had opencv-python & opencv-python-headless installed (both old versions). I uninstalled them using pip and then installed opencv-python==4.8.0.74.
Reacted by dachao .Wang, Brandon Wagstaff, Congyi Mai, Spencer Gable-Cook, Vinaya Bomnale, Kingmin, Parham Zolfaghari, honglyua, Abhishek Kashyap, chelizard and 1 more
I uninstalled all my opencv versions (found by pip list)
Manually deleted the cv2 in the system python's dist-packages directory
Finally, re-installing opencv-python-headless
Worked fine with the latest version 4.8.1.78
How to Fix Stale cv2 / opencv-python Confilcts
# uninstall all versions of opencv
pip uninstall $(pip list --format=freeze | grep opencv)# remove the stale cv2 dist-packages directory# (pay attention to your location and python version)
rm -rf /usr/local/lib/python3.10/dist-packages/cv2/
# I'm installing on a Docker image that I don't intend to give a display,# so I use the -headless package to avoid installing libgl stuff# install latest opencv-python
pip install opencv-python-headless
# (or opencv-python if you have the gl stuff)
python -c "import cv2; print(cv2.__version__)"
4.8.1
Bonus Context
I'm setting this up on the nvcr.io/nvidia/pytorch:23.10-py3 image, which comes with opencv 4.7.0 installed, and I too was installing requirements for YOLOv8 and anomalib, which bumped me to the latest opencv-python, and then I found out that I wanted opencv-python-headless, because I'm doing a headless docker system, and this package doesn't depend on libgl.so.1.
If you need to use opencv-python, it should work with this fix, just make sure you have the dependencies that fix the missing libgl.so.1 problem:
Fix for libgl.so.1 if you need to use opencv-python
Activity
asmorkalov commentedon Aug 10, 2023
DictValue class type is defined in
cv2/dnn/__init__.pyi:60and works with interpreter:Tested with Ubuntu, python 3.8 and opencv-python 4.8.0.76 from pip.
VadimLevin commentedon Aug 10, 2023
Can't reproduce
caoandong commentedon Aug 19, 2023
Can confirm that this issue happens in the latest release by simply running
import cv2.The previous version
opencv-python==4.8.0.74works fine,.Maybe it has something to do with the way import work?
VadimLevin commentedon Aug 21, 2023
@caoandong
Can you confirm that you observe an issue in a clean virtual environment?
caoandong commentedon Aug 26, 2023
OK yeah installing from the clean virtual env solves the problem.
I think the issue has something to do with
pip uninstall opencv-pythonnot uninstalling the previously installed version.After searching and removing all previous installed versions of
cv2and reinstallingopencv-pythonit works.thepowerfuldeez commentedon Aug 26, 2023
Thank you! That should solve the problem
alrafiabdullah commentedon Oct 1, 2023
I faced this issue while using YOLOV8. For my case, the docker container had
opencv-python&opencv-python-headlessinstalled (both old versions). I uninstalled them usingpipand then installedopencv-python==4.8.0.74.lyheiyu commentedon Oct 10, 2023
For mac
source activate 'your env'
You can use a lower opencv version
pip install opencv-python==4.5.0XXX
K-Ashik commentedon Nov 5, 2023
opencv-python==4.5.64has solved the problems for me in macbook m1 slicondowngrading the opencv2 (#315)
stillgreyfox commentedon Nov 12, 2023
I was having this issue as well.
cv2in the system python'sdist-packagesdirectoryopencv-python-headlessHow to Fix Stale
cv2/opencv-pythonConfilctsBonus Context
I'm setting this up on the nvcr.io/nvidia/pytorch:23.10-py3 image, which comes with opencv 4.7.0 installed, and I too was installing requirements for YOLOv8 and anomalib, which bumped me to the latest opencv-python, and then I found out that I wanted opencv-python-headless, because I'm doing a headless docker system, and this package doesn't depend on libgl.so.1.
If you need to use opencv-python, it should work with this fix, just make sure you have the dependencies that fix the missing libgl.so.1 problem:
Fix for libgl.so.1 if you need to use opencv-python
libgl.so.1 opencv-python fix
cv2.dnn issue. Refer: opencv/opencv-python#884
soulteary commentedon Jan 7, 2024
The above processing process was made into a small tool, thanks @stillgreyfox
https://github.com/soulteary/opencv-fixer