How do I import Zbar into my Python 3.4 script?

ltadams21 picture ltadams21 · Oct 26, 2015 · Viewed 13.4k times · Source

I am pretty new to programming, and have never used Zbar before. I am trying to write a simple script that will allow me to import Zbar and use it to decode a barcode image. I already have a script set up to decode text from images that uses Pytesseract and Tesseract OCR, but I need to be able to decode barcodes as well. I have Windows 7 32 bit, and and am using Python 3.4. I have already installed Zbar and have used it from the command line successfully to decode their barcode sample. I have tried using >pip install zbar, but I keep getting the error:

"fatal error C1083: Cannot open include file: 'zbar.h': No such file or directory error: command 'C:\Program Files\Microsoft Visual Studio 10.0\VC\BIN\cl.exe' failed with exit status 2"

Getting the pytesseract OCR was painless but I have wasted a lot of time on this barcode portion of it, any help or alternatives would be much appreciated.

Answer

Rutrus picture Rutrus · Jun 24, 2017

Seven months later you accepted the best answer, a simple solution for python3.4+ on Windows OS appeared. A ctypes-based wrapper around the zbar barcode reader, a package named pyzbar. If you are on Linux, you need to install libzbar0 but you said you are using Windows and the zbar library is included as dll with the Windows Python wheels. Today, all you need to do is launch:

pip install pyzbar

References for the package: