最近需要在电脑中识别二维码(QR CODE),根据pyzbar教程却得不到正常结果,报
FileNotFoundError: Could not find module 'C:\Users\biewang\AppData\Local\Programs\Python\Python39\lib\site-packages\pyzbar\libzbar-64.dll' (or one of its dependencies). Try using the full path with constructor syntax.
版本信息
Python 3.9.6
pyzbar 0.1.8
安装
pip install pillow #用于图片文件读取
pip install pyzbar #用于二维码识别
脚本
import pyzbar.pyzbar as pyzbar
from PIL import Image
import os
# 识别code
def decode_qr_code(img_path):
if not os.path.exists(img_path):
raise FileExistsError(img_path)
return pyzbar.decode(Image.open(img_path), symbols=[pyzbar.ZBarSymbol.QRCODE])
print(decode_qr_code(".\\Dingtalk_20210830173929.jpg")[0].data)
报错思路
操作顺序 | 原因 | 结果 |
---|---|---|
检查libzbar-64.dll是否存在 | 报错信息Could not find module 'C:\Users\biewang\AppData\Local\Programs\Python\Python39\lib\site-packages\pyzbar\libzbar-64.dll' | 存在,排除该原因 |
检查libzbar-64.dll依赖,使用dumpbin 或者查看源码工程 | 报错信息(or one of its dependencies) | 缺少msvcr120.dll |
解决思路
操作顺序 | 原因 | 结果 |
---|---|---|
在C:\Windows\System32(windows运行时动态库目录,现在的系统基本是windows_x64,里面放的就是64位动态库) orC:\Windows\SysWOW64 (windows_x64上存放32位动态库的目录)查找msvcr120.dll | 缺少msvcr120.dll ,这个动态库是Microsoft Visual C++ 2013 的运行时库,一般系统已带,检查windows的动态库32位和64位看看是否安装该动态库 | System32目录存在msvcr120_clr0400.dll SysWOW64目录存在 msvcr120.dll |
得知32位的库是默认的,而64位msvcr120_clr0400.dll
被暂时移除了(重命名)了
解决方法
将64位的msvcr120_clr0400.dll移动到pyzbar目录C:\Users\biewang\AppData\Local\Programs\Python\Python39\Lib\site-packages\pyzbar
,并修改文件名变成正确名字msvcr120.dll
,使它仅作用于该目录(被libzbar-64.dll同级引用),问题解决