Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: module 'cv2.dnn' has no attribute 'DictValue' #40

Closed
Scikud opened this issue Sep 6, 2023 · 12 comments
Closed

AttributeError: module 'cv2.dnn' has no attribute 'DictValue' #40

Scikud opened this issue Sep 6, 2023 · 12 comments

Comments

@Scikud
Copy link

Scikud commented Sep 6, 2023

When trying to run the cli on any pdf I run into the the error above. Here's the stacktrace.

Traceback (most recent call last):
  File "/usr/local/bin/nougat", line 5, in <module>
    from predict import main
  File "/usr/local/lib/python3.8/dist-packages/predict.py", line 17, in <module>
    from nougat import NougatModel
  File "/usr/local/lib/python3.8/dist-packages/nougat/__init__.py", line 7, in <module>
    from .model import NougatConfig, NougatModel
  File "/usr/local/lib/python3.8/dist-packages/nougat/model.py", line 16, in <module>
    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

@kannan-scalers-ai
Copy link

@Scikud This seems to be an issue with latest version of opencv (4.8.0.76).

Downgrading the package to 4.8.0.74 version works for me.
You can refer the issue posted on opencv repo here opencv/opencv-python#884

@hbbolaji
Copy link

@Scikud I was able to fix it by removing line 169 from "/Users/apple/anaconda3/lib/python3.11/site-packages/cv2/typing/init.py" file, it seems to be the problem

comment out line 169 like so
# LayerId = cv2.dnn.DictValue

@dave-mf
Copy link

dave-mf commented Oct 7, 2023

@hbbolaji Thanks, it worked for me

@soulteary
Copy link

try

# 1. download the autofix tool
pip install opencv-fixer==0.2.5
# 2. execute
python -c "from opencv_fixer import AutoFix; AutoFix()"

code: https://github.com/soulteary/opencv-fixer

@HomaTaherpour
Copy link

@Scikud I was able to fix it by removing line 169 from the "/Users/apple/anaconda3/lib/python3.11/site-packages/cv2/typing/init.py" file, it seems to be the problem

comment out line 169 like so # LayerId = cv2.dnn.DictValue

@Scikud I was able to fix it by removing line 169 from "/Users/apple/anaconda3/lib/python3.11/site-packages/cv2/typing/init.py" file, it seems to be the problem

comment out line 169 like so # LayerId = cv2.dnn.DictValue

I was searching for long time and try each and everything but just this way worked with one difference I changed line 168.

@JakobLS
Copy link

JakobLS commented Jan 25, 2024

It's now working after upgrading to the latest version 4.9.0.80.

pip install opencv-python --upgrade

@devarshi16
Copy link

@Scikud I was able to fix it by removing line 169 from "/Users/apple/anaconda3/lib/python3.11/site-packages/cv2/typing/init.py" file, it seems to be the problem

comment out line 169 like so # LayerId = cv2.dnn.DictValue

In linux the corresponding file was in /usr/local/lib/python3.8/dist-packages/cv2/typing/__init__.py

Made the change and it's working now.

@abhirupghosh
Copy link

How is this issue closed? I still get the same error with the most up to date packages.

@soulteary
Copy link

How is this issue closed? I still get the same error with the most up to date packages.

Just choose any of the solutions above, whether it's reinstalling or using the repair tool I wrote.

I saw some of my previous comments were downvoted, and some of them were incomprehensible, so I took them casually, and those who downvoted them were just happy. hhh

This is from an ordinary user, a developer not related to this repository.

@abhirupghosh
Copy link

How is this issue closed? I still get the same error with the most up to date packages.

Just choose any of the solutions above, whether it's reinstalling or using the repair tool I wrote.

I saw some of my previous comments were downvoted, and some of them were incomprehensible, so I took them casually, and those who downvoted them were just happy. hhh

This is from an ordinary user, a developer not related to this repository.

Hey, thanks for your response! I used opencvfixer and also tried to reinstall my installation of opencv on a fresh install. The issue persists.

@soulteary
Copy link

Maybe it's because this module has been upgraded?

https://github.com/soulteary/opencv-fixer/blob/main/opencv_fixer/autofix.py

Here are the complete steps for my repair, you can see if it is of reference value

@StefanosNtouvlis
Copy link

@Scikud I was able to fix it by removing line 169 from "/Users/apple/anaconda3/lib/python3.11/site-packages/cv2/typing/init.py" file, it seems to be the problem

comment out line 169 like so # LayerId = cv2.dnn.DictValue

You sir are a beauty.
On the latest update (macOS) it's line 171

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests