Running package through gui shows gui error

Issue #103 new
Daniel Benamy
created an issue

Here's my

from setuptools import setup

APP = ['']
DATA_FILES = ['check.svg']
    'argv_emulation': False, # some people say this helps running pkg in gui

    options={'py2app': OPTIONS},

I'm building with:

rm -rf build/ dist/ &&
python py2app --use-pythonpath --no-strip

When I run ./dist/ it works fine.

But when I double click on, I get a gui msg box that says "valium error". Screenshots at and

I'm using: OSX 10.8.2 I've not activate a virtual env so I'm using the system python (2.7.2). Although py2app is installed in a virtual env. * Details of the virtual env are listed in

How do I track this down?

Thanks so much!


Comments (8)

  1. Ronald Oussoren repo owner

    The build likely won't work from the command-line as well when you remove "--use-pythonpath", when that variable is set the application honors the PYTHONPATH variable and that variable set in your build shell but won't be set when you double-click the app (because Finder won't read the shell startup files).

    For some reason py2app doesn't copy some files that you need in the app bundle, and that's likely and old bug that you run into because you end up using the py2app version that Apple ships.

    The easiest workaround is likely to either install a newer py2app versions in the system install of python, or install all software you need in the VE (where you have a newer version of py2app). I've fixed a number of bugs related to not copying resources/modules since the version that Apple uses was released (which was several months before 10.8.0 was released).

  2. Daniel Benamy reporter

    Thanks for the reply!

    Here's the latest:

    I activated the virtualenv so it should be using py2app 0.7.3.

    If I build with OR without --use-pythonpath

    rm -rf build/ dist/; python py2app --use-pythonpath --no-strip


    rm -rf build/ dist/; python py2app --no-strip

    and run it from the command line or by double clicking, I get a little gui error msg box that says

    Valium has encountered a fatal error, and will now terminate.
    A Python runtime not could [typo is in error message] be located.  You may need to install a framework build of Python, or edit the PyRuntimeLocations array in this application's Info.plist file.

    I don't know why I was getting that error when importing Foundation last time and not now. I haven't installed anything new in the VE or recreated it.

    Does this new error message make sense to you?

    Thanks for all your help!

  3. Daniel Benamy reporter

    I may have figured out why I wasn't seeing the import error: I think I was seeing it when running the program but when I was just testing all the variations of building the app, I was just building, and not running each.

    Anyway, where I'm at now is that the VE looks like

    $ pip freeze

    At least for now, I've installed pyqt using brew so it's not in the VE. I added it to my PYTHONPATH so I can access it

    $ echo $PYTHONPATH

    I'm able to run the app normally, with python

    When I build with --use-pythonpath and NO --alias rm -rf build/ dist/; python py2app --use-pythonpath --no-strip and run it from the command line, I get the gui error about the python runtime not being found..

    With --use-pythonpath and --alias, it works.

    With --alias and NO --use-pythonpath, I get a PyQt4 import error.

    With NO --alias and NO --use-pythonpath, I get the "no runtime located" gui error.

  4. Daniel Benamy reporter

    I tried another approach. I symlinked pyqt4 and sip into my virtualenv:

    cd ~/.virtualenvs/valium/lib/python2.7/site-packages/
    ln -s /usr/local/lib/python2.7/site-packages/PyQt4/
    ln -s /usr/local/lib/python2.7/site-packages/

    I cleared PYTHONPATH: export PYTHONPATH=''

    An alias build works

    rm build/ dist/; python py2app --no-strip --alias && echo "Running Valium" && ./dist/

    A normal build fails with "Python runtime not could be located. You may need to install a framework build of Python, or edit the PyRuntimeLocations array in this application's Info.plist file."

    rm build/ dist/; python py2app --no-strip && echo "Running Valium" && ./dist/
  5. Ronald Oussoren repo owner

    What is the output of the following command:

    $ otool -vL $(which python)

    Py2app needs a version of python that is dynamicly linked to the interpreter (either libpython.dylib or Python.framework). This is because py2app copies a small C executable into your app bundle that performs some initialization before starting the interpreter, and the code in that C exectuble uses the python shared library.

  6. Daniel Benamy reporter


    $ workon valium
    $ otool -vL $(which python)
        @executable_path/../.Python (compatibility version 2.7.0, current version 2.7.2)
        time stamp 2 Wed Dec 31 19:00:02 1969
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
        time stamp 2 Wed Dec 31 19:00:02 1969
        /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 741.0.0)
        time stamp 2 Wed Dec 31 19:00:02 1969
  7. Daniel Benamy reporter

    Summary: I got it to work by switching to python installed by brew.

    I played around with the apple/system python and couldn't get it to work. Then I: removed virtualenv and virtualenvwrapper which I had installed system wide, set up my /etc/paths to put brew stuff (/usr/local/...) first, brew installed python, and re-installed all my python stuff with a new VE that allows access to system packages.

    Then I was able to do a normal build: rm build/ dist/; python py2app and it works from the console and by double clicking in the gui.

    I've spent sooo many hours trying to get this working. It would be super helpful if py2app could detect if the python or environment is bad and give a clear error.

    I'll leave this open in case you have any questions, but feel free to close it.

    Thanks so much!!

  8. Ronald Oussoren repo owner

    I try to enhance py2app whenever I get reports like this (either by adding code for support a new build/install configuration, or by adding an explicit warning).

    I don't fully understand yet why py2app didn't work for you. Part of the problem is that you ran with the (old, and fairly buggy) system install of py2app and there is little I can do about that because Guido closely guards the keys to his time machine :-). You also ran into problems with a newer release though, and I'll have to reproduce your environment to fully investigate that problem.

  9. Log in to comment