1. Ronald Oussoren
  2. py2app
  3. Issues

Issues

Issue #85 resolved

sandboxing interaction issue

Ronald Oussoren
repo owner created an issue

Sandboxing (as introduced in OSX 10.7) doesn't like py2app's executable stubs, in particular the fact that the stub is not linked to the AppKit framework.

This can be seen bij creating a GUI application (using any GUI toolkit) with a file dialog (open/save), the application will crash when trying to show the dialog.

There is an easy workaround for the crash: recompile the executable stub and explicitly link with AppKit.framework.

That is a suboptimal solution though:

1) the stub code uses dynamic loading tricks to avoid linking to AppKit, those tricks could be removed

2) the dynamic loading tricks are there for a reason: without those tricks the application will trigger compatibility modes in system framework (that is, some frameworks behave slightly differently when the binary is linked with older SDKs).

The solution for that would be to recompile the stubs with every new OSX release. That should only be necessary for the 'intel', 'i386' and 'x86_64' targets (the other ones include PPC code)

Comments (10)

  1. FalkorSystems

    Hello. I am not familiar with mac development, but I'm trying to use py2app to build a Qt Python app for the Mac App store. Can you point me to a reference that will help me implement the above workaround?

    Thanks.

  2. FalkorSystems

    I tried to do what was recommended here:

    http://python.6.n6.nabble.com/How-to-make-py2app-app-stub-link-to-Cocoa-framework-td2157525.html

    But that did not work. These are my errors:

    3/30/13 7:04:01.840 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/__init__.pyc
    3/30/13 7:04:01.843 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/error.pyc
    3/30/13 7:04:01.846 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/tokens.pyc
    3/30/13 7:04:01.848 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/events.pyc
    3/30/13 7:04:01.851 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/nodes.pyc
    3/30/13 7:04:01.853 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/loader.pyc
    3/30/13 7:04:01.855 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/reader.pyc
    3/30/13 7:04:01.891 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/scanner.pyc
    3/30/13 7:04:01.897 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/parser.pyc
    3/30/13 7:04:01.899 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/composer.pyc
    3/30/13 7:04:01.905 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/constructor.pyc
    3/30/13 7:04:01.915 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/resolver.pyc
    3/30/13 7:04:01.923 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/dumper.pyc
    3/30/13 7:04:01.933 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/emitter.pyc
    3/30/13 7:04:01.935 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/serializer.pyc
    3/30/13 7:04:01.940 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/representer.pyc
    3/30/13 7:04:01.942 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/cyaml.pyc
    3/30/13 7:04:01.979 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-create /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/PySide/__init__.pyc
    3/30/13 7:04:02.049 PM sandboxd: ([11451]) DeFisheye(11451) deny file-read-data /usr/X11/lib/libpng15.15.dylib
    3/30/13 7:04:02.050 PM [0x0-0xb15b15].com.falkorsystems.defisheye: argvemulator warning: fetching events failed
    3/30/13 7:04:02.050 PM [0x0-0xb15b15].com.falkorsystems.defisheye: Traceback (most recent call last):
    3/30/13 7:04:02.050 PM [0x0-0xb15b15].com.falkorsystems.defisheye:   File "/Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/__boot__.py", line 352, in <module>
    3/30/13 7:04:02.050 PM [0x0-0xb15b15].com.falkorsystems.defisheye:     _run()
    3/30/13 7:04:02.050 PM [0x0-0xb15b15].com.falkorsystems.defisheye:   File "/Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/__boot__.py", line 347, in _run
    3/30/13 7:04:02.050 PM [0x0-0xb15b15].com.falkorsystems.defisheye:     exec(compile(source, path, 'exec'), globals(), globals())
    3/30/13 7:04:02.050 PM [0x0-0xb15b15].com.falkorsystems.defisheye:   File "/Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/defisheye", line 43, in <module>
    3/30/13 7:04:02.050 PM [0x0-0xb15b15].com.falkorsystems.defisheye:     import cv2
    3/30/13 7:04:02.050 PM [0x0-0xb15b15].com.falkorsystems.defisheye: ImportError: dlopen(/Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/lib-dynload/cv2.so, 2): Library not loaded: /usr/X11/lib/libpng15.15.dylib
    3/30/13 7:04:02.050 PM [0x0-0xb15b15].com.falkorsystems.defisheye:   Referenced from: /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/MacOS/../Frameworks/libopencv_highgui.2.4.4.dylib
    3/30/13 7:04:02.050 PM [0x0-0xb15b15].com.falkorsystems.defisheye:   Reason: no suitable image found.  Did find:
    3/30/13 7:04:02.050 PM [0x0-0xb15b15].com.falkorsystems.defisheye:  /usr/X11/lib/libpng15.15.dylib: open() failed with errno=1
    3/30/13 7:04:02.119 PM DeFisheye: DeFisheye Error
    3/30/13 7:04:03.683 PM lsboxd: @AE relay 61657674:72617070
    3/30/13 7:04:03.703 PM com.apple.launchd.peruser.501: ([0x0-0xb15b15].com.falkorsystems.defisheye[11451]) Exited with code: 255
    
  3. Ronald Oussoren reporter

    Deny-file-write-unlink errors are caused by python trying to byte-compile source, see issue #101.

    The other problem is that your application seems to reference shared libraries that aren't in the application bundle, and that shouldn't happen and appears to indicate a problem with py2app.

    Do you have a way to reproduce the problem (a simple script that you can share that also has the import error for opencv)?

  4. James Kruth

    We're experiencing intermittent crashing from very simple sandboxed Python apps on dialog close (the dialogs show just fine). I'm wondering if this issue is related?

  5. FalkorSystems

    I'm happy to share with you on github if you want, we're going to open source this once it is ready for release anyway.

    But in the meantime here a simple repro, without the deny-file-write-unlink error:

    import cv2
    

    (Most of the below I got from George's posting here of course =)

    Here's my entitlements file

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>com.apple.security.app-sandbox</key>   <true/>
    </dict>
    </plist>
    

    My build script

    python setup.py py2app 
    
    cd dist
    
    # Sign
    codesign --force --verify --verbose \
        --sign "3rd Party Mac Developer Application" \
        --entitlements ../DeFisheye.entitlements \
        DeFisheye.app
    
    codesign --force --verify --verbose \
      --sign "3rd Party Mac Developer Application" \
      --entitlements ../DeFisheye.entitlements \
      DeFisheye.app/Contents/Frameworks/Python.framework/Versions/2.7
    
    codesign --force --verify --verbose \
      --sign "3rd Party Mac Developer Application" \
      --entitlements ../DeFisheye.entitlements \
      DeFisheye.app/Contents/MacOS/python
    
    codesign -vvv -d DeFisheye.app
    

    And the relevant snippet of my setup.py:

    if (platform.system() == "Darwin"):
        from setuptools import setup
    
        APP = ['defisheye']
        DATA_FILES = ['config']
        OPTIONS = {'argv_emulation': True,
                   'packages': 'PySide,yaml',
                   'includes': 'cv,cv2',
                   'argv_inject': '--gui',
                   'iconfile': 'pixmaps/defisheye.icns',
                   'plist': {
                       'CFBundleIdentifier': 'com.falkorsystems.defisheye',
                       'CFBundleName': 'DeFisheye',
                       'CFBundleVersion': '0.1.0',
                       'CFBundleShortVersionString': '0.1.0',
                       'CFBundleDocumentTypes': [ { 'CFBundleTypeName': 'MP4' } ],
                       'LSApplicationCategoryType': 'public.app-category.video',
                   }
        }
    
        setup(
            name='DeFisheye',
            app=APP,
            data_files=DATA_FILES,
            options={'py2app': OPTIONS},
            setup_requires=['py2app'],
        )
    

    Thanks!

  6. Log in to comment