Issue 768391: hardcoded python paths (original) (raw)
I tried to use the new version of idle that is now integrated into 2.3b2, but I got an error when I tried to run /usr/local/lib/python2.3/idlelib/idle:
% /usr/local/lib/python2.3/idlelib/idle Traceback (most recent call last): File "./idle", line 8, in ? import PyShell File "./PyShell.py", line 19, in ? from Tkinter import * File "/usr/lib/python2.2/lib-tk/Tkinter.py", line 35, in ? import _tkinter # If this fails your Python may not be configured for Tk ImportError: No module named _tkinter
I'm using python2.3b2 on MacOSX 10.2.6, compiled from source with standard options.
Apparently the builtin 2.2 version of Python is being used, even though $PYTHONHOME is not set (according to the manpages, this should make it default to /usr/local, and not /usr as seems to be the case).
This is due to the fact that this executable script contains a shebang declaration with a hardcoded python path:
% head -1 /usr/local/lib/python2.3/idlelib/idle #!/usr/bin/python
This should be replaced by the standard shebang declaration: #! /usr/bin/env python
I checked to see if there were any other *.py files in /usr/local/lib/python2.3 suffering from similar problems, and found the following files to be affected:
/usr/local/lib/python2.3/cgi.py: #! /usr/local/bin/python /usr/local/lib/python2.3/test/test_bz2.py: #!/usr/bin/python /usr/local/lib/python2.3/test/test_largefile.py: #!python /usr/local/lib/python2.3/test/test_optparse.py: #!/usr/bin/python
The files /usr/local/bin/idle, /usr/local/bin/pydoc and /usr/local/bin/pycolor also have a hardcoded python path: % head -1 idle pycolor pydoc ==> idle <== #!/usr/local/bin/python
==> pycolor <== #!/usr/local/bin/python
==> pydoc <== #!/usr/local/bin/python
These should similarly be changed to #! /usr/bin/env python
Logged In: YES user_id=45365
Idle on MacOSX isn't run from the commandline: you doubleclick the icon in the finder. And what gets launched then is an applet, which doesn't look at #! paths or anything.
If you want to run idle from the command line you could do that, but you would have to use #!/usr/bin/pythonw, not #!/usr/bin/python.