(MacBook M1):raise ImportError('Unable to find zbar shared library') ImportError: Unable to find zbar shared library

Mac OS X :

brew install zbar 

Install this Python wrapper; use the second form to install dependencies of the command-line scripts:

pip install pyzbar

I tried these steps but i'm still getting the bellow error

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

Upvotes: 11

Views: 8363

Answers (2)

Carniolian
Carniolian

Reputation: 21

The python package pyzbar loads the external library libzbar using the function ctypes.util.find_library(), which looks-up the environment variable DYLD_LIBRARY_PATH. Thus, you can add the following code to your ~/.bash_profile:

export DYLD_LIBRARY_PATH=$(brew --prefix zbar)/lib:$DYLD_LIBRARY_PATH

For other libraries, ctypes.util.find_library() might check LD_LIBRARY_PATH instead.

However, please mind that libzbar will still not be found when invoking python from /usr/bin/env. This is because the System Integrity Protection Guide blocks propagating all dynamic linker environment variables such as DYLD_LIBRARY_PATH. See also the following post.

Upvotes: 2

Charles
Charles

Reputation: 351

This worked for me. Have a try.

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

From https://stackoverflow.com/a/71904987/14882853

Upvotes: 25

Related Questions