Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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_emulation': True}

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)
like image 857
Grahame Thomson Avatar asked Apr 09 '11 18:04

Grahame Thomson


People also ask

Can you use py2app on Windows?

You can create standalone applications with Python scripts by using py2app on OS X or py2exe on Windows.

Can you write Mac apps with Python?

py2app is a Python setuptools command which will allow you to make standalone application bundles and plugins from Python scripts. py2app is similar in purpose and design to py2exe for Windows. Py2app must be run on macOS and cannot be used to cross build macOS applications on Windows or Linux.

How do I create a Python application on Mac?

You can interactively create an app project with Run Shell Script action, then paste in your script in its editor, select your shell program (/usr/bin/python), finally save the project. And you have yourself a Mac native app. Automator can also be driven by AppleScript.


1 Answers

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.

like image 170
Giacomo Avatar answered Nov 04 '22 09:11

Giacomo