开发者

how do I use py2app?

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_emulati开发者_开发问答on': True}

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)


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.


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).


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜