(MacBook M1):引发 ImportError('无法找到 zbar 共享库') ImportError:无法找到 zbar 共享库

问题描述 投票:0回答:2

Mac OS X :

brew install zbar 

安装这个Python包装器;使用第二种形式安装命令行脚本的依赖项:

pip install pyzbar

我尝试了这些步骤,但仍然收到以下错误

File "/Users/something/opt/anaconda3/envs/muenv/lib/python3.8/site-packages/pyzbar/wrapper.py", line 136, in zbar_function
    return prototype((fname, load_libzbar()))
  File "/Users/something/opt/anaconda3/envs/muenv/lib/python3.8/site-packages/pyzbar/wrapper.py", line 115, in load_libzbar
    libzbar, dependencies = zbar_library.load()
  File "/Users/something/opt/anaconda3/envs/muenv/lib/python3.8/site-packages/pyzbar/zbar_library.py", line 65, in load
    raise ImportError('Unable to find zbar shared library')
ImportError: Unable to find zbar shared library
python python-3.8 zbar
2个回答
14
投票

这对我有用。尝试一下。

mkdir ~/lib
ln -s $(brew --prefix zbar)/lib/libzbar.dylib ~/lib/libzbar.dylib

来自https://stackoverflow.com/a/71904987/14882853


0
投票

包使用函数

libzbar
加载
ctypes.util.find_library()
,该函数查找环境变量
DYLD_LIBRARY_PATH
。因此,您可以将以下代码添加到您的
~/.bash_profile

if [[ -z $DYLD_LIBRARY_PATH ]]; then
  export DYLD_LIBRARY_PATH=$(brew --prefix zbar)/lib
else
  export DYLD_LIBRARY_PATH=$(brew --prefix zbar)/lib:$DYLD_LIBRARY_PATH
fi

对于其他库,

ctypes.util.find_library()
可能会检查
LD_LIBRARY_PATH

© www.soinside.com 2019 - 2024. All rights reserved.