{"id":5709,"library":"pyzbar","title":"pyzbar","description":"pyzbar is a Python library that provides bindings for the open-source ZBar barcode reading library. It allows users to read one-dimensional barcodes and QR codes from various image sources, including PIL/Pillow images, OpenCV/NumPy ndarrays, and raw bytes. The current version is 0.1.9. While some sources suggest active maintenance and regular updates, external analysis indicates an inactive maintenance status with no new PyPI releases in the past 12 months as of late 2025.","status":"maintenance","version":"0.1.9","language":"en","source_language":"en","source_url":"https://github.com/NaturalHistoryMuseum/pyzbar/","tags":["barcode","qr code","image processing","computer vision"],"install":[{"cmd":"pip install pyzbar","lang":"bash","label":"Standard Installation"},{"cmd":"pip install pyzbar[scripts]","lang":"bash","label":"Installation with command-line script dependencies (e.g., Pillow)"},{"cmd":"brew install zbar","lang":"bash","label":"macOS (install zbar shared library)"},{"cmd":"sudo apt-get install libzbar0","lang":"bash","label":"Linux (install zbar shared library)"}],"dependencies":[{"reason":"pyzbar is a Python wrapper for the zbar C library, which must be installed separately on non-Windows systems.","package":"zbar","optional":false},{"reason":"Required for image processing when using PIL/Pillow Image objects, and for command-line scripts.","package":"Pillow","optional":true},{"reason":"Required for image processing when using OpenCV/NumPy ndarrays.","package":"opencv-python","optional":true}],"imports":[{"note":"The `decode` function is located within the `pyzbar.pyzbar` submodule, not directly under `pyzbar`.","wrong":"import pyzbar; pyzbar.decode(...)","symbol":"decode","correct":"from pyzbar.pyzbar import decode"},{"note":"Used to specify particular barcode types to decode.","symbol":"ZBarSymbol","correct":"from pyzbar.pyzbar import ZBarSymbol"}],"quickstart":{"code":"from pyzbar.pyzbar import decode\nfrom PIL import Image\nimport os\n\n# Assuming an image file named 'barcode.png' exists in the current directory\n# For a real application, replace with a path to your image or a file handle\nimage_path = os.environ.get('PZ_TEST_IMAGE_PATH', 'pyzbar/tests/code128.png') # Using a test image from the repo for runnable example\n\ntry:\n    # Open the image file using Pillow\n    img = Image.open(image_path)\n\n    # Decode any barcodes in the image\n    barcodes = decode(img)\n\n    if barcodes:\n        for barcode in barcodes:\n            print(f\"Decoded Data: {barcode.data.decode('utf-8')}\")\n            print(f\"Barcode Type: {barcode.type}\")\n            print(f\"Location (Rect): {barcode.rect}\")\n    else:\n        print(\"No barcodes found in the image.\")\n\nexcept FileNotFoundError:\n    print(f\"Error: Image file not found at {image_path}. Please provide a valid path.\")\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")","lang":"python","description":"This quickstart demonstrates how to use `pyzbar` to decode barcodes from an image using the Pillow library. It opens an image file and then calls the `decode` function to extract barcode information, printing the decoded data and type. Remember to replace `image_path` with the actual path to your barcode image."},"warnings":[{"fix":"Install `zbar` using your system's package manager (e.g., `brew install zbar` on macOS, `sudo apt-get install libzbar0` on Debian/Ubuntu).","message":"On non-Windows operating systems (macOS, Linux), the underlying `zbar` shared library must be installed separately from `pyzbar`. `pyzbar` itself is just a Python wrapper. Failure to install `zbar` will result in an `ImportError` or 'Unable to find zbar shared library' error.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Install the Visual C++ Redistributable Packages for Visual Studio 2013 (both x64 and x86 versions) relevant to your Python installation.","message":"On Windows, if you encounter an `ImportError` when importing `pyzbar`, it may be due to missing Visual C++ Redistributable Packages for Visual Studio 2013. This is especially true if `libiconv.dll` or `libzbar-64.dll` (or 32-bit equivalents) are not found, even if they appear to be present.","severity":"gotcha","affected_versions":"All versions on Windows"},{"fix":"Use `from pyzbar.pyzbar import decode` for the correct import path.","message":"When decoding images, the `decode` function should be imported from `pyzbar.pyzbar`. A common mistake is trying to call `pyzbar.decode()` directly.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Call `.decode('utf-8')` on the `data` attribute, for example: `barcode.data.decode('utf-8')`.","message":"The `data` attribute of the `Decoded` object (the barcode content) is a byte string (`bytes`). You need to explicitly decode it to a string (`str`) using a suitable encoding (e.g., `'utf-8'`) if you want to work with text.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Update your `zbar` shared library to a newer version that supports orientation if this feature is critical for your application.","message":"The `orientation` field of the `Decoded` object might be `None` if your installed `zbar` library is an older release (pre-2019 fork) that does not support decoding barcode orientation.","severity":"gotcha","affected_versions":"Older zbar library installations"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}