2

Is it possible to manually replace or specify the location of a .dylib on Mac OSX when using pyinstaller?

I'm getting the error when trying to open my completed .app

Traceback (most recent call last):
  File "DeepMeerkat/main.py", line 3, in <module>
    import cv2
  File "/Library/Python/2.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 546, in load_module
    module = imp.load_module(fullname, fp, filename, ext_tuple)
ImportError: dlopen(/Users/ben/Documents/DeepMeerkat/Installer/dist/Lib/cv2.so, 2): Library not loaded: @loader_path/libpng16.16.dylib
  Referenced from: /Users/ben/Documents/DeepMeerkat/Installer/dist/Lib/libopencv_imgcodecs.3.3.dylib
  Reason: Incompatible library version: libopencv_imgcodecs.3.3.dylib requires version 48.0.0 or later, but libpng16.16.dylib provides version 45.0.0
Failed to execute script main

I have no problem loading cv2 in python outside of the app, or any other problems with open, which was installed with homebrew.

Poking around, I think it is extremely likely the error comes from pyinstaller grabbing libpng from X11 (/opt/X11/include/libpng16) when it needs to be grabbing from Homebrew's folders (/usr/local/Cellar/libpng/1.6.32/)

How can I use a hook to specify which libpng I want?

1
  • manually replacing the file worked, but won't scale well. I'll keep this open.
    – bw4sz
    Sep 18, 2017 at 21:52

1 Answer 1

4

I had the same problem, the answer lay in editing the .spec file. Add the following line after a = Analysis...:

a.binaries = a.binaries - TOC([('libpng16.16.dylib',None,None)])

This has the effect of removing the offending dylib from the relevant TOC file which solves the conflict.

2
  • This fix works and is (unfortunately) still relevant with Python 3.7, pyinstaller 3.5, while running on macos 10.14.6
    – TSeymour
    Nov 7, 2019 at 20:43
  • Yes, Python 3.7, pyinstaller version 3.6 here. This worked.
    – bpops
    Jun 24, 2020 at 1:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.