7

Ok - here goes. I am trying to learn how to use py2app, so I created a simple python file; just hello_world.py

#! /usr/bin/env python
def main():
print "Hello"

if __name__=="__main__":
    main()

I followed a tutorial and did the following:

py2applet --make-setup hello.py
python setup.py py2app -A

This created two sub-directories (build and dist), within dist there was a file called hello.app. I attempted to launch it through the GUI but it launched for less than a second and then disappeared. I then went to the CL but simply trying to run it didn't work so I used:

python hello.app

with the following error:

/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python: can't find '__main__.py' in 'hello.app'

I've spent all day googling but can't find any tutorials or guides etc. I'm really stuck :-(

I don't know if this helps but this is what is in the setup.py

"""
This is a setup.py script generated by py2applet

Usage:
    python setup.py py2app
"""

from setuptools import setup

APP = ['hello.py']
DATA_FILES = []
OPTIONS = {'argv_emulation': True}

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)
Grahame Thomson
  • 201
  • 2
  • 3
  • 6

3 Answers3

9

You have successfully used py2app - it just opens, prints "hello" and then closes really quickly!

If you want to see something, then make it pause for a bit:

print "Hello"
import time
time.sleep(5)

time.sleep pauses a program for the number of seconds given.

Giacomo
  • 412
  • 3
  • 10
5

You really only want to use py2app with GUI apps, or ones that run in the background.

If you want to run the py2app-built application from the command line, you need to execute the binary inside the application bundle; the bundle itself is not directly executable, so something like this:

dist/hello.app/Contents/MacOS/hello

For scripts that just print to stdout you might try Platypus (though it doesn't do the dependency-packaging stuff of py2app).

Nicholas Riley
  • 43,532
  • 6
  • 101
  • 124
1

It seems that it was working all along - the script was just running so quickly I didn't have a chance to see it. If anyone comes across this go to http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html and follow the tutorial. Please also read the answers given and the replies I left.

Grahame Thomson
  • 201
  • 2
  • 3
  • 6