Cv2 has no attribute dnn OpenCV 4.6.0 Python 3.9.13 Conda Environment

Hello people!

While uploading the Yolo model to OpenCV 4.6.0 installed using conda install opencv on VS Code(MacOS, M1 chip) on Python version 3.9.13 I receive the “cv2 has no dnn attribute” error. Does anyone know what is the issue? How to resolve this?

please paste the result of
print(cv2.getBuildInformation())
to us, so we can judge better

General configuration for OpenCV 4.6.0 =====================================
  Version control:               unknown

  Extra modules:
    Location (extra):            /private/var/folders/sy/f16zz6x50xz3113nwtb9bvq00000gp/T/abs_506zufg7xt/croots/recipe/opencv-suite_1664548331847/work/opencv_contrib-4.6.0/modules
    Version control (extra):     unknown

  Platform:
    Timestamp:                   2022-09-30T14:47:33Z
    Host:                        Darwin 20.6.0 x86_64
    CMake:                       3.22.1
    CMake generator:             Ninja
    CMake build tool:            /var/folders/sy/f16zz6x50xz3113nwtb9bvq00000gp/T/abs_506zufg7xt/croots/recipe/opencv-suite_1664548331847/_build_env/bin/ninja
    Configuration:               Release

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3 SSSE3
      requested:                 DETECT
    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      SSE4_1 (16 files):         + SSE4_1
      SSE4_2 (1 files):          + SSE4_1 POPCNT SSE4_2
      FP16 (0 files):            + SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (3 files):             + SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (29 files):           + SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
      AVX512_SKX (3 files):      + SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX

  C/C++:
    Built as dynamic libs?:      YES
    C++ standard:                11
    C++ Compiler:                /var/folders/sy/f16zz6x50xz3113nwtb9bvq00000gp/T/abs_506zufg7xt/croots/recipe/opencv-suite_1664548331847/_build_env/bin/x86_64-apple-darwin13.4.0-clang++  (ver 12.0.0)
    C++ flags (Release):         -march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -stdlib=libc++ -fvisibility-inlines-hidden -std=c++14 -fmessage-length=0 -isystem /Users/diasmashikov/opt/anaconda3/envs/yoloenv/include -fdebug-prefix-map=/var/folders/sy/f16zz6x50xz3113nwtb9bvq00000gp/T/abs_506zufg7xt/croots/recipe/opencv-suite_1664548331847/work=/usr/local/src/conda/opencv-suite-4.6.0 -fdebug-prefix-map=/Users/diasmashikov/opt/anaconda3/envs/yoloenv=/usr/local/src/conda-prefix -D__STDC_CONSTANT_MACROS   -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -Wno-deprecated-enum-enum-conversion -Wno-deprecated-anon-enum-enum-conversion -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections  -O3 -DNDEBUG  -DNDEBUG
    C++ flags (Debug):           -march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -stdlib=libc++ -fvisibility-inlines-hidden -std=c++14 -fmessage-length=0 -isystem /Users/diasmashikov/opt/anaconda3/envs/yoloenv/include -fdebug-prefix-map=/var/folders/sy/f16zz6x50xz3113nwtb9bvq00000gp/T/abs_506zufg7xt/croots/recipe/opencv-suite_1664548331847/work=/usr/local/src/conda/opencv-suite-4.6.0 -fdebug-prefix-map=/Users/diasmashikov/opt/anaconda3/envs/yoloenv=/usr/local/src/conda-prefix -D__STDC_CONSTANT_MACROS   -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -Wno-deprecated-enum-enum-conversion -Wno-deprecated-anon-enum-enum-conversion -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections  -g  -DDEBUG -D_DEBUG
    C Compiler:                  /var/folders/sy/f16zz6x50xz3113nwtb9bvq00000gp/T/abs_506zufg7xt/croots/recipe/opencv-suite_1664548331847/_build_env/bin/x86_64-apple-darwin13.4.0-clang
    C flags (Release):           -march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -isystem /Users/diasmashikov/opt/anaconda3/envs/yoloenv/include -fdebug-prefix-map=/var/folders/sy/f16zz6x50xz3113nwtb9bvq00000gp/T/abs_506zufg7xt/croots/recipe/opencv-suite_1664548331847/work=/usr/local/src/conda/opencv-suite-4.6.0 -fdebug-prefix-map=/Users/diasmashikov/opt/anaconda3/envs/yoloenv=/usr/local/src/conda-prefix   -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -Wno-deprecated-enum-enum-conversion -Wno-deprecated-anon-enum-enum-conversion -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections  -O3 -DNDEBUG  -DNDEBUG
    C flags (Debug):             -march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -isystem /Users/diasmashikov/opt/anaconda3/envs/yoloenv/include -fdebug-prefix-map=/var/folders/sy/f16zz6x50xz3113nwtb9bvq00000gp/T/abs_506zufg7xt/croots/recipe/opencv-suite_1664548331847/work=/usr/local/src/conda/opencv-suite-4.6.0 -fdebug-prefix-map=/Users/diasmashikov/opt/anaconda3/envs/yoloenv=/usr/local/src/conda-prefix   -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -Wno-deprecated-enum-enum-conversion -Wno-deprecated-anon-enum-enum-conversion -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections  -g  -DDEBUG -D_DEBUG
    Linker flags (Release):      -Wl,-pie -Wl,-headerpad_max_install_names -Wl,-dead_strip_dylibs -Wl,-rpath,/Users/diasmashikov/opt/anaconda3/envs/yoloenv/lib -L/Users/diasmashikov/opt/anaconda3/envs/yoloenv/lib  -Wl,-dead_strip  
    Linker flags (Debug):        -Wl,-pie -Wl,-headerpad_max_install_names -Wl,-dead_strip_dylibs -Wl,-rpath,/Users/diasmashikov/opt/anaconda3/envs/yoloenv/lib -L/Users/diasmashikov/opt/anaconda3/envs/yoloenv/lib  -Wl,-dead_strip  
    ccache:                      NO
    Precompiled headers:         NO
    Extra dependencies:
    3rdparty dependencies:

  OpenCV modules:
    To be built:                 alphamat aruco bgsegm bioinspired calib3d ccalib core cvv datasets dpm face features2d flann freetype fuzzy gapi hdf hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor ml objdetect optflow phase_unwrapping photo plot python3 quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching tracking video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
    Disabled:                    world
    Disabled by dependency:      barcode dnn_objdetect dnn_superres mcc text wechat_qrcode
    Unavailable:                 cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev dnn java julia matlab ovis python2 sfm ts viz
    Applications:                -
    Documentation:               NO
    Non-free algorithms:         NO

  GUI:                           QT5
    QT:                          YES (ver 5.15.2 )
      QT OpenGL support:         NO
    Cocoa:                       YES

  Media I/O: 
    ZLib:                        /Users/diasmashikov/opt/anaconda3/envs/yoloenv/lib/libz.dylib (ver 1.2.12)
    JPEG:                        /Users/diasmashikov/opt/anaconda3/envs/yoloenv/lib/libjpeg.dylib (ver 90)
    PNG:                         /Users/diasmashikov/opt/anaconda3/envs/yoloenv/lib/libpng.dylib (ver 1.6.37)
    TIFF:                        /Users/diasmashikov/opt/anaconda3/envs/yoloenv/lib/libtiff.dylib (ver 42 / 4.1.0)
    JPEG 2000:                   OpenJPEG (ver 2.3.0)
    OpenEXR:                     build (ver 2.3.0)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    GStreamer:                   YES (1.14.0)
    AVFoundation:                YES

  Parallel framework:            GCD

  Trace:                         YES (built-in)

  Other third-party libraries:
    Intel IPP:                   2020.0.0 Gold [2020.0.0]
           at:                   /private/var/folders/sy/f16zz6x50xz3113nwtb9bvq00000gp/T/abs_506zufg7xt/croots/recipe/opencv-suite_1664548331847/work/build/3rdparty/ippicv/ippicv_mac/icv
    Intel IPP IW:                sources (2020.0.0)
              at:                /private/var/folders/sy/f16zz6x50xz3113nwtb9bvq00000gp/T/abs_506zufg7xt/croots/recipe/opencv-suite_1664548331847/work/build/3rdparty/ippicv/ippicv_mac/iw
    Eigen:                       YES (ver 3.3.7)
    Custom HAL:                  NO

  Python 3:
    Interpreter:                 /Users/diasmashikov/opt/anaconda3/envs/yoloenv/bin/python3 (ver 3.9.13)
    Libraries:                   /Users/diasmashikov/opt/anaconda3/envs/yoloenv/lib/libpython3.9.dylib (ver 3.9.13)
    numpy:                       /Users/diasmashikov/opt/anaconda3/envs/yoloenv/lib/python3.9/site-packages/numpy/core/include (ver 1.16.6)
    install path:                lib/python3.9/site-packages/cv2/python-3.9

  Python (for build):            /Users/diasmashikov/opt/anaconda3/envs/yoloenv/bin/python

  Java:                          
    ant:                         NO
    JNI:                         /opt/MacOSX10.10.sdk/System/Library/Frameworks/JavaVM.framework/Headers /opt/MacOSX10.10.sdk/System/Library/Frameworks/JavaVM.framework/Headers /opt/MacOSX10.10.sdk/System/Library/Frameworks/JavaVM.framework/Headers
    Java wrappers:               NO
    Java tests:                  NO

  Install to:                    /Users/diasmashikov/opt/anaconda3/envs/yoloenv
-----------------------------------------------------------------

how on earth did that happen ?

any chance, you can post the cmake(console) output here ?
(should have some valuable hints there)

there’s the issue.

never ever do that. random packages on conda are almost SURE to be junk. if you must, make sure you’re getting something from conda-forge.

the only official packages live in PyPI and you install them with pip/pip3. the name of the primary package is opencv-python. an alternative (NOT an addition!) is opencv-contrib-python.

1 Like

Thank you so much! I am relatively new, but can I use pip to install packages in Conda environments? Or is it just meaningless?