dromalpalli
dromalpalli

Reputation: 117

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.

Upvotes: 1

Views: 1730

Answers (2)

ajcubest
ajcubest

Reputation: 11

I had the same issue, and the above fix didn't work. Following the paths /opt/local/lib/libexempi.dylib and /opt/homebrew/lib/libexempi.dylib made me realize I didn't actually have a .dylib file in either folder, despite having run brew install exempi.

So I manually installed exempi (which is supposedly unnecessary when you use brew, but there I was) by following these steps:

  1. Download and extract Exempi
curl -L -o exempi-2.5.0.tar.bz2 https://libopenraw.freedesktop.org/download/exempi-2.5.0.tar.bz2
tar -xjf exempi-2.5.0.tar.bz2
cd exempi-2.5.0
  1. Configure Boost (may need to brew install boost)
export BOOST_ROOT=$(brew --prefix boost)
export BOOST_INCLUDEDIR=$BOOST_ROOT/include
export BOOST_LIBRARYDIR=$BOOST_ROOT/lib
./configure
  1. Compile & install Exempi to desired location (may need to brew install cmake, expat)
make
sudo make install

This installed it to /opt/homebrew/lib, and you can check that the path exists with ls /opt/homebrew/lib/libexempi.dylib.

If it isn't there, it might be in /usr/local/lib, you can either change your _load_exempi to include that path or add --prefix=/opt/homebrew to your ./configure step. That didn't happen to me so I'm not too sure, but to anyone whose brew install exempi isn't handling all of this, this fixed my issues.

Upvotes: 1

Jonathan G
Jonathan G

Reputation: 25

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.

Upvotes: 3

Related Questions