0

我有这个从图像中读取条形码的脚本。

from PIL import Image
import zbar

scanner = zbar.ImageScanner()
scanner.parse_config('enable')
pil = Image.open('zbartest2.png').convert('L')
width, height = pil.size
raw = pil.tostring()
image = zbar.Image(width, height, 'Y800', raw)
scanner.scan(image)

for symbol in image:
    print 'decoded', symbol.type, 'symbol', '"%s"' % symbol.data
del(image)

当我将此脚本放在 python 主目录中时,C:\Python27它可以正常工作。

C:\myscript但是,当我将此脚本放在主目录之外时,例如import zbar - module The specified module could not be found.

是什么导致了问题?

我在 Windows Xp 32bits SP3 上使用 Python 2.7 32bits

编辑:

我正在使用运行模块命令(F5)从空闲窗口执行它;完整的回溯

Traceback (most recent call last):
   File "C:\myscript\test.py", line 2, in <module>
   import zbar
ImportError: DLL load failed: The specified module could not be found.

当我输入时,import zbar; print zbar.__file__ 我得到以下消息

C:\Python27\lib\site-packages\zbar.pyd
4

2 回答 2

0

似乎 dll 在 c:\Python27 中,但 c:\Python27 不在搜索路径中。尝试添加

import sys

sys.path.append("C:\Python2.7")

在导入 zbar 之前添加到您的代码中。

如果工作正常,那么您必须配置 python 的搜索路径才能添加 C:\Python27. 我在 linux 上工作,对不起,我不能帮助你在 Windows 上这样做。

编辑:嗯,我不喜欢写一个我不知道该怎么做的答案。所以我做了一些研究,寻找一些可以帮助我弄清楚你的问题的文档。并在这里找到它正在导入 PYD 文件

于 2013-12-16T15:36:51.857 回答
-3

确保您将要导入的所有文件与此脚本位于同一目录中

于 2013-12-16T03:56:02.233 回答