py2applet open terminal only

311 views Asked by At

I have a python script which waits for user input and then print the input string. Say this script is called "run.py".

The script run.py imports some other python script I wrote, the folder structure is :

+ py_app
    - run.py
    + util
        - __init__.py
        - a.py
        - b.py
        - c.py

Now I hope I can wrap this little app in a .app file so that the other mac user can just double click to run the script.

I used the py2applet to do the job:

py2applet --make-setup run.py 

The setup.py:

from setuptools import setup

APP = ['run.py']
DATA_FILES = []
OPTIONS = {}

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

and then

python setup.py py2app -A

running py2app
running build_py
creating build
creating build/bdist.macosx-10.11-intel
creating build/bdist.macosx-10.11-intel/lib
creating build/bdist.macosx-10.11-intel/lib/leancloud_util
copying util/__init__.py -> build/bdist.macosx-10.11-intel/lib/util
copying util/a.py -> build/bdist.macosx-10.11-intel/lib/util
copying util/b.py -> build/bdist.macosx-10.11-intel/lib/util
copying util/c.py -> build/bdist.macosx-10.11-intel/lib/util
creating path/to/app/build/bdist.macosx-10.11-intel/python2.7-semi_standalone
creating path/to/app/build/bdist.macosx-10.11-intel/python2.7-semi_standalone/app
creating path/to/app/build/bdist.macosx-10.11-intel/python2.7-semi_standalone/app/collect
creating path/to/app/build/bdist.macosx-10.11-intel/python2.7-semi_standalone/app/temp
creating path/to/app/dist
creating build/bdist.macosx-10.11-intel/python2.7-semi_standalone/app/lib-dynload
creating build/bdist.macosx-10.11-intel/python2.7-semi_standalone/app/Frameworks
*** creating application bundle: run ***
Done!

Everything seem to be work fine but when I click the generated app, the terminal dose not show up......

I changed my run.py to make it real simple:

#!/usr/bin/env python    
# -*- coding: utf-8 -*-

from util.a import a
from util.b import b
from util.c import c

if __name__ == "__main__":
    print '111111 ...'

But still, nothing happens when I click the app and of course the script runs fine when I call it in the terminal:

python run.py

I am not sure what could be the problem. Any advice will be appreciated, thanks :)

1

There are 1 answers

0
Fabio Marzocca On

If your script contains system calls, be aware that once packaged, the app looses the system PATH so the scripts cannot be found anymore in the PATH.

My suggestion is to add this code at the very beginning of the program:

os.environ["PATH"] += "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"