[Idle-dev] use_subprocess issues...

Tony Lownds tony@lownds.com
Wed, 25 Sep 2002 10:12:00 -0700


Hi Kurt,

>  >
>>  Yes, sys.exec_prefix + 'bin/python' is reliable BUT unfortunately that
>>  will not include the magic .app directory in argv[0], so running
>>  Tkinter (or any other type of GUI) won't work. But it would work for
>  > non-GUI scripts.

It may not be future-proof but there are ways to find the interpreter 
for the current python release. So, I am pursuing your suggestion of 
special casing in the spawn_subprocess module. Patch at the end of 
this file - please let me know if this isn't what you had in mind.

I think we can lay this issue to rest!

>I haven't done much with OS X beyond fiddling with its command prompt
>at the local computer store.  But it sure acts like xxxBSD.  emacs -nw
>works fine, for example.  I didn't try Python, but IMHO any real Unix
>should provide the Python interpreter at the command prompt :)

:)

>Does the Python2.2 that Apple is shipping with Jaguar include Tk?

Nope

>According to Jack's MacPython page, it runs the interpreter from the
>command line.

The python2.2 that Apple ships is actually included through the 
Darwin project. That is the Kernel plus BSD but no graphics. So, 
since the bundled python is built w/o access to any Mac APIs nor X11 
(as neither is included in Darwin), Tkinter isn't even possible to 
include...

>If I start Python from the Linux command line I can then start the
>Tkinter test applet:
>
>[kbk@float ~/proj/sandbox/idlefork]$ python 
>Python 2.3a0 (#3, May  8 2002, 23:37:01)
>[GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
>Type "help", "copyright", "credits" or "license" for more information.
>>>>  import Tkinter
>>>>  Tkinter._test
><function _test at 0x4041048c>
>  >>> Tkinter._test()
>
>at which point the tk applet window appears on my desktop.
>
>
>I would think that it would be useful to get that working on Jaguar
>before proceeding.

tlownds@perhamlite:~% pythonw
Python 2.3a0 (#1, Sep 16 2002, 14:01:50)
[GCC 3.1 20020420 (prerelease)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>  import Tkinter
>>>  Tkinter._test()

Note the subtle difference.... "pythonw" must be invoked.

-Tony



+++ PyShell.py  25 Sep 2002 16:53:33 -0000
@@ -160,11 +160,24 @@
      rpcclt = None
      rpcpid = None

-    def spawn_subprocess(self):
-        w = ['-W' + s for s in sys.warnoptions]
-        args = [sys.executable] + w + ["-c", "__import__('run').main()",
+    def spawn_subprocess(self):        
+        w = ['-W' + s for s in sys.warnoptions]       
+        args = [self.find_executable()] + w + ["-c", 
"__import__('run').main()",
                                         str(self.port)]
          self.rpcpid = os.spawnv(os.P_NOWAIT, args[0], args)
+
+    def find_executable(self):
+        if sys.platform == 'darwin' and sys.executable.count('.app'):
+            # On Mac OS X, avoid calling sys.executable because it ignores
+            # command-line options (sys.executable is an applet)
+            #
+            # Instead, find the executable by looking relative to
+            # sys.prefix.
+            executable = os.path.join(sys.prefix, 'Resources', 'Python.app',
+                                'Contents', 'MacOS', 'python')
+            return executable
+        else:
+            return sys.executable

      def start_subprocess(self):
          addr = ("localhost", self.port)