This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Finding subprocess.py depends on how IDLE is opened
Type: Stage: resolved
Components: IDLE Versions: Python 2.7, Python 2.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: George.Patterson, amaury.forgeotdarc, ned.deily
Priority: normal Keywords:

Created on 2011-06-02 22:49 by George.Patterson, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg137497 - (view) Author: George Patterson (George.Patterson) Date: 2011-06-02 22:49
I'm uncertain this is a bug, but it seems persistent over several machines and I can't figure out where the issue lies.

Most of my troubleshooting has been on a MacBook Pro with Mac OS X version 10.6.7. I have a simple python script 'test.py':

  import subprocess
  subprocess.Popen(['xterm'])

If I run this script by opening it in IDLE using the mouse, it crashes. If I run the same script in an IDLE that I launch by typing 'idle' in a terminal, it doesn't crash. What's going on?  Is this a bug? Or am I just doing something terribly wrong?
Obviously, my interest is not in running this simple script, but it contains the minimum part of the real script which reproduces the error.  

I've repeated this error on one machine(MacBook Pro with Mac OS X version 10.6.7) using either of two versions of Python, 2.6.6 or 2.7.1.  On one machine(Mac Pro OS X version 10.6.7) using Python 2.6.6, on two other machines(IMacs with either OS X version 10.6.7 or 10.6.5) using Python 2.7.1.  I include below only the info for the 2.7.1.

Python 2.7.1 was the 32-bit version Mac OS X 32-bit i386/PPC Installer (2.7.1) for Mac OS X 10.3 through 10.6 [2] (sig) from here (http://www.python.org/download/releases/2.7.1/).



Details: 


1.  Launch IDLE by right clicking test.py and "open with" IDLE (2.7.1).  I "run module".  Pasted below are the contents from the Python Shell.  Included at the bottom is the sys.path for IDLE opened in this manner.
I've also find this error if I open the IDLE located in Applications/Python 2.7/ and then open "test.py" and run it.


Python 2.7.1 (r271:86882M, Nov 30 2010, 09:39:13) 
[GCC 4.0.1 (Apple Inc. build 5494)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>> 

Traceback (most recent call last):
  File "/Users/georgepatterson/test.py", line 2, in <module>
    subprocess.Popen(['xterm'])
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 672, in __init__
    errread, errwrite)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1202, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
>>> import sys
>>> for p in sys.path: print p

/Users/georgepatterson
/Users/georgepatterson/Documents
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
>>> 




2.  Type "idle" in a terminal window.  Open test.py and "run module".
When run in this manner, the terminal window is opened properly.  I've pasted the contents of the Python Shell below with the sys.path also. 
In case it matters, "which idle" at the terminal prompt points here
/Library/Frameworks/Python.framework/Versions/2.7/bin/idle



Python 2.7.1 (r271:86882M, Nov 30 2010, 09:39:13) 
[GCC 4.0.1 (Apple Inc. build 5494)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>> 
>>> import sys
>>> for p in sys.path: print p

/Users/georgepatterson
/Library/Frameworks/Python.framework/Versions/2.7/bin
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
>>>
msg137498 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2011-06-02 23:03
sys.path is probably not relevant here (it's used to import python modules). Can you print the value of os.environ['PATH'] instead?
msg137505 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2011-06-03 03:14
The difference in behavior you are seeing does indeed have to do with the PATH environment variable.  When you start IDLE via a terminal shell, it inherits the PATH value from your shell environment.  path_helper(8) sets the default value for a login shell PATH by consulting the entries in /etc/paths.d/. On OS X 10.6, that includes /usr/X11/bin, which is where xterm is located.  However, when you launch IDLE from the Finder, either by double-clicking on the IDLE app icon or by opening a file using IDLE as the default app (as you are doing in test 1), a shell is not involved and the PATH inherited by the app environment is slightly different.  In paticular, /etc/paths.d is not consulted and so /usr/X11/bin is not on the path.  As Amaury suggested, you should be able to see that by looking at PATH in both cases.  For IDLE.app launched from the Finder, you'll probably see something like:

   >>> os.environ['PATH']
   '/usr/bin:/bin:/usr/sbin:/sbin'

While it is possible to change the default environment variables for processes launched (see http://developer.apple.com/library/mac/#qa/qa1067/_index.html), it is rarely necessary or desirable to do that.  For this case, the simplest solution is to supply the absolute path to 'xterm':

  import subprocess
  subprocess.Popen(['/usr/X11/bin/xterm'])

Or you could get fancier by modifying PATH yourself.
History
Date User Action Args
2022-04-11 14:57:18adminsetgithub: 56456
2011-06-03 03:14:54ned.deilysetstatus: open -> closed

type: crash ->

nosy: + ned.deily
messages: + msg137505
resolution: not a bug
stage: resolved
2011-06-02 23:03:04amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg137498
2011-06-02 22:49:05George.Pattersoncreate