Error with opencv and libjpeg, using py2app

198 views
Skip to first unread message

Oksana Meledin

unread,
Jul 15, 2017, 7:48:40 PM7/15/17
to wxPython-users
I am trying to create a standalone Mac GUI app.

I used wxPython (wxpython-phoenix 4.0.0a4) to create the GUI.

I am trying to use py2app (0.14) to create a standalone app that can be used on a different machine not requiring a python installation.

Initially, I tried using anaconda python, but ran into grave difficulties. Now, I'm using homebrew python2.7.

The app runs fine on my local machine fine.

But on the target machine, I get the following error. "import cv2" is looking for libjpeg in a hardcoded location instead of inside the standalone Contents.
(There is a version of libjpeg inside: /repos/ct/dist/CtAnnotator.app/Contents/Frameworks/libjpeg.8.dylib.)


Traceback (most recent call last):
  File "/Volumes/PciSsd/repos/ct/dist/CtAnnotator.app/Contents/Resources/__boot__.py", line 98, in <module>
    _run()
  File "/Volumes/PciSsd/repos/ct/dist/CtAnnotator.app/Contents/Resources/__boot__.py", line 82, in _run
    exec(compile(source, path, 'exec'), globals(), globals())
  File "/Volumes/PciSsd/repos/ct/dist/CtAnnotator.app/Contents/Resources/CtAnnotator.py", line 7, in <module>
    import cv2
ImportError: dlopen(/Volumes/PciSsd/repos/ct/dist/CtAnnotator.app/Contents/Resources/lib/python2.7/lib-dynload/cv2.so, 2): Library not loaded: /usr/local/opt/jpeg/lib/libjpeg.8.dylib
  Referenced from: /Volumes/PciSsd/repos/ct/dist/CtAnnotator.app/Contents/Frameworks/libopencv_highgui.2.4.13.dylib
  Reason: image not found

Does anyone have ideas on how to proceed?

Matt Newville

unread,
Jul 15, 2017, 10:16:26 PM7/15/17
to wxpytho...@googlegroups.com


You might be able to use `install_name_tool` to change where that opencv dynamic library is looking for libjpeg (and use `otool -L` to verify where it is actually looking before and after changing). 

I would guess that if you need to do it once, you may need to do it for another dozen or more cases.  You may also have to fiddle with the resulting app every time you build a new version. So I cannot say I recommend it, but it might work.

--Matt Newville

Igor Korot

unread,
Jul 16, 2017, 10:31:43 AM7/16/17
to wxpytho...@googlegroups.com
Hi, Oksana,
Did you use wxPython binary from the official wxPython site or you
build it yourself?

Thank you.

>
>
>
> You might be able to use `install_name_tool` to change where that opencv
> dynamic library is looking for libjpeg (and use `otool -L` to verify where
> it is actually looking before and after changing).
>
> I would guess that if you need to do it once, you may need to do it for
> another dozen or more cases. You may also have to fiddle with the resulting
> app every time you build a new version. So I cannot say I recommend it, but
> it might work.
>
> --Matt Newville
>
> --
> You received this message because you are subscribed to the Google Groups
> "wxPython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to wxpython-user...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Message has been deleted

Oksana Meledin

unread,
Jul 16, 2017, 2:33:35 PM7/16/17
to wxPython-users
I downloaded the wheel from wxpython.org snapshot builds: https://wxpython.org/Phoenix/snapshot-builds/

Chris Barker

unread,
Jul 16, 2017, 2:39:07 PM7/16/17
to wxpython-users
well, it's an opencv problem, so wx is probably unrelated.

py2app is _supposed_ to re-write the linking to fix this issue, so it may work to do it by hand for this one case -- hopefully the others did work right...

I'd post a question on the python-mac list:


very low traffic these days, but the primary py2app developer is on it.

You could also try PyInstaller -- it's working a bit better for us these days.

-CHB





On Sun, Jul 16, 2017 at 11:12 AM, Courosh Mehanian <cou...@gmail.com> wrote:

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris....@noaa.gov
Message has been deleted

Oksana Meledin

unread,
Sep 30, 2017, 10:18:00 PM9/30/17
to wxPython-users
Hi Matt,

Thanks for your suggestion. libjpeg did not show up among the list of libraries when I run otool -L:

/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 22.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.50.2)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 489.0.0)
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1349.64.0)

Therefore when I run:

      install_name_tool -change libjpeg.8.dylib @executable_path/../Frameworks/libjpeg.8.dylib CtAnnotator

and then otool -L again, there is no change in output. And there is no change in behavior of the App. Still produces the same error.

Matt Newville

unread,
Oct 1, 2017, 10:37:06 AM10/1/17
to wxpytho...@googlegroups.com
On Sat, Sep 30, 2017 at 9:18 PM, Oksana Meledin <oksana...@gmail.com> wrote:
Hi Matt,

Thanks for your suggestion. libjpeg did not show up among the list of libraries when I run otool -L:

/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 22.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.50.2)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 489.0.0)
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1349.64.0)

Therefore when I run:

      install_name_tool -change libjpeg.8.dylib @executable_path/../Frameworks/libjpeg.8.dylib CtAnnotator

and then otool -L again, there is no change in output. And there is no change in behavior of the App. Still produces the same error.




I think you will need to find out which opencv-related dynamic libraries are looking for libjpeg and not finding it, and change the path for those libraries to point to the actual location of libjeg.  By actual location, I mean the location it will be at when the code in your application is actually run, so probably inside your py2app-created Application folder.

This will almost certainly take some trial and error, and you might find other cases where such changes are needed.  I cannot say that this will be easy or fun.  I haven't tried to use py2app in a long time.

Hope that helps,

--Matt

Reply all
Reply to author
Forward
0 new messages