Registry / serialization / pyzxing

pyzxing

JSON →
library1.1.1pypypi✓ verified 87d ago

PyZXing is a Python wrapper for the popular ZXing Java library, providing functionality primarily for decoding 1D and 2D barcodes (like QR codes) from image files or in-memory image bytes. It currently stands at version 1.1.1 and has an irregular release cadence, largely driven by updates to the underlying ZXing Java core.

pip install pyzxing
INSTALL
IMPORT
SIG · PYZXING
P
pyzxing
serializationpythonv1.1.1
Install
4.1s avg
Import
783ms
Disk
95MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.1.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.803s · 91.6MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 4.1s · import 0.762s · 88MB
95MB installed
● package 95MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

BarCodeReader
from pyzxing import BarCodeReader

Initializes the BarCodeReader and attempts to decode a barcode from a specified image file. Note that `pyzxing` calls an external Java process, requiring a JRE installation. Results are returned as a list of dictionaries.

import os from pyzxing import BarCodeReader # For demonstration, create a dummy image file if it doesn't exist # In a real scenario, 'barcode.png' would be an actual image with a barcode. dummy_image_path = 'barcode.png' if not os.path.exists(dummy_image_path): print(f"Warning: '{dummy_image_path}' not found. Decoding might fail. Please provide a real barcode image.") # Example of how you might create a dummy (non-barcode) file to prevent FileNotFoundError with open(dummy_image_path, 'w') as f: f.write('This is not an image.') try: reader = BarCodeReader() # Decode from a file path results = reader.decode(dummy_image_path) if results: for result in results: print(f"Decoded text: {result.get('parsed', 'N/A')}") print(f"Format: {result.get('format', 'N/A')}") else: print(f"No barcode found in {dummy_image_path}") except Exception as e: print(f"An error occurred: {e}") finally: # Clean up dummy file if created for demonstration if not os.path.exists(dummy_image_path): os.remove(dummy_image_path)
Debug
Known issues
gotchaPyZXing is a wrapper around a Java library. A Java Runtime Environment (JRE) must be installed and accessible via your system's PATH for PyZXing to function correctly.
fix
Install a JRE (e.g., OpenJDK) for your operating system and ensure the `java` executable is in your system's PATH, or specify its path via the `java_path` argument to `BarCodeReader`.
affects: All versions
gotchaThe `pyzxing` library primarily focuses on barcode *decoding*. While the underlying ZXing Java library supports encoding, this Python wrapper does not directly expose encoding functionality through its public API.
fix
For barcode encoding, consider using other Python libraries designed for encoding (e.g., `qrcode` for QR codes) or directly calling the ZXing Java library if encoding is a critical requirement.
affects: All versions
gotchaPyZXing executes the Java ZXing library as a subprocess. This can introduce overhead, making it less suitable for high-performance, low-latency barcode processing tasks compared to pure Python or C/C++ based solutions.
fix
Evaluate performance requirements. For extremely high-throughput scenarios, consider alternatives or pre-processing images to reduce the number of `pyzxing` calls. Ensure adequate system resources and an efficient JRE installation.
affects: All versions
gotchaIf you don't provide a valid `java_path` to the `BarCodeReader` constructor, PyZXing relies on the `java` executable being found in your system's PATH environment variable. If it's not found, you'll encounter a `FileNotFoundError`.
fix
Either add your JRE's `bin` directory to your system's PATH, or initialize the reader with the explicit path to your Java executable: `reader = BarCodeReader(java_path='/path/to/your/java')`.
affects: All versions
Errors
Common errors & fixes
FileNotFoundError: [Errno 2] No such file or directory: 'java'
The Python interpreter could not find the 'java' executable in the system's PATH, which is required to run the underlying ZXing Java library.
fix
Ensure a Java Runtime Environment (JRE) is installed and its 'bin' directory is added to your system's PATH environment variable. Alternatively, instantiate `BarCodeReader` with the full path to the `java` executable, e.g., `BarCodeReader(java_path='/usr/bin/java')`.
java.lang.NoClassDefFoundError: com/google/zxing/MultiFormatReader
The ZXing core JAR file required by `pyzxing` is either missing, corrupted, or not properly located by the Java process. This can happen if the PyZXing installation is incomplete or environment variables interfere.
fix
Reinstall `pyzxing` (`pip install --force-reinstall pyzxing`). If the issue persists, check for any `CLASSPATH` environment variables that might be overriding the internal one used by `pyzxing`.
java.io.FileNotFoundException: <image_file_path> (No such file or directory)
The image file specified for decoding does not exist at the given path, or the path is incorrect/inaccessible by the Java subprocess.
fix
Verify that the `image_file_path` passed to `reader.decode()` is correct and that the Python process has read permissions for that file and directory. Ensure there are no typos in the file path.
No barcode found in <image_file_path>
PyZXing successfully processed the image but could not detect any valid barcodes. This is not an error in the library's execution, but rather in the content of the image.
fix
Ensure the image contains a clear, high-contrast barcode. Check for image quality, resolution, rotation, and lighting conditions. Try decoding different images known to contain barcodes to rule out image-specific issues.
Upgrade
Version history
1.1.1latest on PyPI · released Sep 11, 2025
Audit
Dependencies
Java Runtime Environment (JRE)requiredRequired to execute the underlying ZXing Java library process.
Agent activity
23 hits · last 30 days
node
20
OpenAI (training)
1
Resources
pyzxing — pip install pyzxing · libregistry