[Python] How to solve Import Error on Python's 'Pyzbar' library?

Discussão em 'Python' iniciado por Stack, Julho 10, 2025.

  1. Stack

    Stack Membro Participativo

    I've just started getting familiar with the library Pyzbar, but when using the decode method I get an error. Here's the code:

    import cv2
    import numpy as np
    import pyzbar

    code_image = cv2.imread("C:\Users\Acer\Desktop\qr.PNG")
    cv2.imshow("QR", code_image)
    cv2.waitKey(0) #this command is to hold the image open after opening it

    from pyzbar import decode
    decoded = pyzbar.decode(code_image)
    print(decoded)


    qr.PNG is just a picture of a QR Code. OpenCV displays the image just fine but it's the decoding part that doesn't work:


    Traceback (most recent call last): File "C:/Users/Acer/Desktop/ML >Projects/Projects/OpenCV/QR_Code_Detection.py", line 17, in from pyzbar import decode ImportError: cannot import name decode
    ​

    When excluding this line: from pyzbar import decode

    I get the following error:


    Traceback (most recent call last): File "C:/Users/Acer/Desktop/ML >Projects/Projects/OpenCV/QR_Code_Detection.py", line 17, in decoded = pyzbar.decode(code_image) AttributeError: 'module' object has no attribute 'decode'
    ​

    Hope someone more knowledgeable can help. Thanks a lot.

    Continue reading...

Compartilhe esta Página