[Pythonmac-SIG] #! line and simple dialogs [SOLVED]

Bob Ippolito bob at redivi.com
Sat Oct 2 03:50:36 CEST 2004


On Oct 1, 2004, at 9:06 PM, Nathaniel Gray wrote:

> On Fri, 1 Oct 2004 14:30:21 -0700, Kevin Altis  
> <altis at semi-retired.com> wrote:
>
>> Hmm, I don't know what the explanation of the #! line not working is,
>> but I found the same thing, I had to use /usr/bin/env pythonw to make
>> it work as expected. The error message I received is for tcsh since my
>> system was upgraded from Jaguar and I never bothered to switch to  
>> bash.
>>
>> tcsh: import: Command not found.
>> from: can't read /var/mail/wx.lib
>> tcsh: Badly placed ()'s.
>
> I figured this out.  The problem is that pythonw is a symlink to
> pythonw2.3, which is a shell script, and Darwin won't allow the
> interpreter for one script to be another script.  I ended up using
> this ugly line:
> #!/System/Library/Frameworks/Python.framework/Versions/Current/ 
> Resources/Python.app/Contents/MacOS/Python
>
> Thankfully, Darwin doesn't seem to mind really long #! lines.  The
> proper solution, AFAICT, is to make /usr/bin/pythonw2.3 a symlink to
> the mess I listed above rather than a shell script that wraps the mess
> I listed above.  This is how /usr/bin/python2.3 works, which is why
> #!/usr/bin/python does work (I was mistaken when I reported that it
> didn't).
>
> I'm not sure who to file the bug report with.  Can anybody point me in
> the right direction?

It's not a bug.  The reason pythonw is a shell script is so that the  
argv[0] for the Python interpreter process points to an interpreter  
executable that exists inside of a valid application bundle.  This is  
necessary in order for the WindowServer to accept a connection to your  
process without using undocumented private hacks.  It would be possible  
to do this by means other than a shell script, but "exec" is a  
convenient way of doing this.

You shouldn't really be using bare scripts as GUI applications in the  
first place.  You may want to take a look at py2app (which is basically  
usable at this point, unless you depend on a funky package like PIL or  
pygame):
http://svn.red-bean.com/bob/py2app/trunk/
(which depends on)
http://svn.red-bean.com/bob/macholib/trunk/

>> As for doing simple dialogs I don't know all the Mac-specific options,
>> but wxPython provides all the system dialogs and then some and of
>> course it works the same on Linux, Mac OS X, and Windows. The
>> dialogs.py module provides function wrappers for all of the dialogs so
>> you don't have to worry about creating an instance of the dialog
>> classes, showing the dialog, and then destroying it, instead you just
>> make a function call which is a nice match for modal dialogs. It would
>> be tough to get much simpler than this.
>
> I'm afraid downloading WxPython is too heavyweight.  I'm trying to use
> Python as AppleScript, essentially.  I was thrilled to find appscript,
> makes it feasible to do exactly that, but I need a simple, lightweight
> way to interact with users.  The balance is heavily weighted towards a
> solution that is platform-specific and has few (preferably no)
> dependencies.  Basically I really want an EasyDialogs that works.  ;^)

You could emulate EasyDialogs with PyObjC, which is pretty lightweight.  
  You could also probably convince appscript to do all your dialogs in  
the same way that Applescript does.

Using py2app (or to a lesser extent, bundlebuilder) makes applications  
that have no dependencies anyway, so that part of your argument doesn't  
really hold much water.  Using wxPython would make for relatively large  
standalone applications, but standalone applications nonetheless.

-bob


More information about the Pythonmac-SIG mailing list