Error with opencv and libjpeg, using py2app

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

_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

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?

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

···

On Sat, Jul 15, 2017 at 6:48 PM, Oksana Meledin <oksanameledin@gmail.com> wrote:

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?

Hi, Oksana,

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?

Did you use wxPython binary from the official wxPython site or you
build it yourself?

Thank you.

···

On Sat, Jul 15, 2017 at 10:15 PM, Matt Newville <newville@cars.uchicago.edu> wrote:

On Sat, Jul 15, 2017 at 6:48 PM, Oksana Meledin <oksanameledin@gmail.com> > wrote:

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-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

I downloaded the wheel from wxpython.org snapshot builds: https://wxpython.org/Phoenix/snapshot-builds/

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:

https://mail.python.org/mailman/listinfo/pythonmac-sig

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 courosh@gmail.com wrote:

I downloaded the wheel from the wxpython.org: https://wxpython.org/Phoenix/snapshot-builds/.

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.Barker@noaa.gov

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.

···

On Saturday, July 15, 2017 at 7:16:26 PM UTC-7, Matt Newville wrote:

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

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

···

On Sat, Sep 30, 2017 at 9:18 PM, Oksana Meledin <oksanameledin@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.