Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Zbar DLL load fail

Firstly, I am aware of this similar SO Question but my problem is slightly different and the answer in that question did not solve my problem. So, I am creating a new post here.

I have downloaded Zbar Installler from http://zbar.sourceforge.net/download.html and managed to successfully(no error message) installed.

But, when i run the following script,

import zbar
from PIL import Image

# create a reader
scanner = zbar.ImageScanner()

# configure the reader
scanner.parse_config('enable')

# obtain image data
pil = Image.open('zbartest2.png').convert('L')
width, height = pil.size
raw = pil.tostring()

# wrap image data
image = zbar.Image(width, height, 'Y800', raw)

# scan the image for barcodes
scanner.scan(image)

# extract results
for symbol in image:
    # do something useful with results
    print 'decoded', symbol.type, 'symbol', '"%s"' % symbol.data

# clean up
del(image)

It give me the error message saying that DLL load fail.

Traceback (most recent call last):

File "D:\Profiles\e492507\Desktop\barcode reader\test.py", line 1, in import zbar ImportError: DLL load failed: The specified module could not be found.

but unlike the similar SO question i mentioned above, when i type this in the python IDLE shell, it works without any problem.

import zbar
zbar.version()

(0, 10)

What is causing the problem and how do i fix it?

FYI: I am using Python 2.7.3 on windows Xp pro 32 bits

UPDATE: 1

I found out that if i copy the script and image into python directory C:\Python27\ it works fine without any problem.

However, as soon as i move the script and image into other places, i got the same error message i posted above.

How should i fix this so that i can execute my script anywhere in my computer as long as the barcode image is available?

UPDATE: 2 (JUST FOR INFO: NOT DIRECTLY RELATED TO THE QUESTION)

I am not able to solve this problem using all the methods i have discovered so far.So, i am coming out with my own silly solution.

I am going to use a simple table drawn by reportlab instead of Barcodes and color the cells accordingly ( black for 1 and white for 0) to represents the numbers in binary.

So, number 69 will be something like this

enter image description here

Then, i can use PIL to detect the black and white squares and covert it back into binary then to decimal. FYI, i am only dealing with the decimal numbers. No alphabets nor other stuffs. I know this is pretty silly but desperate times call for desperate measures :P

like image 688
Chris Aung Avatar asked Dec 13 '13 00:12

Chris Aung


2 Answers

It sounds like it's working when the dependent DLL's are somewhere in your PATH and it breaks when you move them elsewhere. The error is specifically saying that it can't load the DLL (or one of its dependencies) so I don't think this is a problem related to the documented instability on Windows systems.

To eliminate this as a possibility, try the following:

  1. Right-click My Computer, and then click Properties.
  2. Click the Advanced tab.
  3. Click Environment variables.
  4. Locate and select the PATH entry and then click Edit.

In the dialog, where it says Variable value, add a semi-colon and then the path to the folder where libzbar-0.dll has been installed.

So, if libzbar-0.dll is in, say, C:\ZBar\Bin and your existing PATH value is :

C:\folder1;C:\folder2;C:\some other folder

Then change the variable value to :

C:\folder1;C:\folder2;C:\some other folder;C:\ZBar\Bin

Then click OK to save all of the changes and - for overkill - reboot. This is because most applications only read environment variables when they first start and it's sometimes confusing if you're not sure whether an application really restarted or was just minimised, for example.

Now see if you can run the Python script from other folders.

like image 64
Roger Rowland Avatar answered Nov 09 '22 06:11

Roger Rowland


The Windows version ofzbaryou installed (zbar-0.10-setup.exe) includes "only command line programs" as stated in itsREADME.windowsfile. It also mentions that "The current (0.10) release of ZBar only comes with command line programs" in the Running ZBar section of the Windows Installation Guide.

In the Windows Installer section of the ZBar bar code reader - Download page it says:

    "Note that the Windows port is in an unstable, testing phase."

In other words, it's not yet consider usable from the Windows version of the Python interpreter.

like image 25
martineau Avatar answered Nov 09 '22 04:11

martineau