'Error installing Exempi 2.5.2 on M1 Macbook Pro running Big Sur

I'm trying to install Exempi 2.5.2 in PyCharm IDE for python in order to read Metadata from a Photoshop psd file.

My code is:

import PIL
from libxmp.utils import file_to_dict
from libxmp import consts
from psd_tools import PSDImage

if __name__ == '__main__':
    print('Hello')

I have installed the following packages in PyCharm: ExifRead Pillow PyBundle brew docopt packbits pip psd-tools3 python-xmp-toolkit pytz setuptools

I get the following Errors: Traceback (most recent call last):

File "/Users/rajnesh/Python/uploadJpeg2SquareSpace.py", line 9, in from libxmp.utils import file_to_dict

File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/libxmp/init.py", line 50, in from .core import XMPMeta, XMPIterator

File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/libxmp/core.py", line 50, in from . import exempi as _cexempi

File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/libxmp/exempi.py", line 69, in EXEMPI = _load_exempi()

File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/libxmp/exempi.py", line 60, in _load_exempi

raise ExempiLoadError('Exempi library not found.')

libxmp.ExempiLoadError: Exempi library not found.

Process finished with exit code 1

The Documentation for Exempi says that I need to have Boost installed. I wonder whether this is the problem. I'm not sure how to install it in PyCharm, since I don't see it as an option amongst the packages.



Solution 1:[1]

I edited my exempi.py after using brew install exempi

def _load_exempi():
    """
    Loads exempi library.
    """
    path = ctypes.util.find_library('exempi')
    if path is None:
        if platform.system().startswith('Darwin'):
            if os.path.exists('/opt/local/lib/libexempi.dylib'):
                # MacPorts starndard location.
                path = '/opt/local/lib/libexempi.dylib'
    if path is None:
        m1_path = '/opt/homebrew/lib/libexempi.dylib'
        if os.path.exists(m1_path):
            path = m1_path
            
    if path is None:
        raise ExempiLoadError('Exempi library not found.')

    if os.name != "nt":
        EXEMPI = ctypes.CDLL(path)
    else:
        EXEMPI = ctypes.WinDLL(path)

    return EXEMPI

to be specific, this is what I added.

if path is None:
        m1_path = '/opt/homebrew/lib/libexempi.dylib'
        if os.path.exists(m1_path):
            path = m1_path

Then it worked.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jonathan G