Error with opencv and libjpeg, using py2app

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Error with opencv and libjpeg, using py2app

Oksana Meledin
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?

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Error with opencv and libjpeg, using py2app

Matt Newville


On Sat, Jul 15, 2017 at 6:48 PM, Oksana Meledin <[hidden email]> 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?


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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Error with opencv and libjpeg, using py2app

Igor Korot
Hi, Oksana,

On Sat, Jul 15, 2017 at 10:15 PM, Matt Newville
<[hidden email]> wrote:

>
>
> On Sat, Jul 15, 2017 at 6:48 PM, Oksana Meledin <[hidden email]>
> 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?

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 [hidden email].
> For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Error with opencv and libjpeg, using py2app

Courosh Mehanian
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Error with opencv and libjpeg, using py2app

Oksana Meledin
In reply to this post by Igor Korot
I downloaded the wheel from wxpython.org snapshot builds: 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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Error with opencv and libjpeg, using py2app

Chris Barker - NOAA Federal
In reply to this post by Courosh Mehanian
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 <[hidden email]> 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 [hidden email].
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

[hidden email]

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Error with opencv and libjpeg, using py2app

Oksana Meledin
In reply to this post by Matt Newville
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


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

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Error with opencv and libjpeg, using py2app

Oksana Meledin
In reply to this post by Matt Newville
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

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Error with opencv and libjpeg, using py2app

Matt Newville


On Sat, Sep 30, 2017 at 9:18 PM, Oksana Meledin <[hidden email]> 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

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.