Python version changes, sys.executable does not

Jeffrey Froman jeffrey at
Sun Jul 22 09:21:40 CEST 2007

Jim Langston wrote:

> I think it's because your python directory is in the path before your
> python2.5 directory.

Thanks for the tip. In fact, /usr/local/bin/python (2.5) is on my PATH
before /usr/bin/python (2.3).

I did find the problem however -- it turns out that caching the executable
path is a feature of the bash shell, possibly a buggy one. After installing
the new executable in /usr/local/bin, bash claimed to be running that
executable, but was actually invoking the cached "python"
at /usr/bin/python.

What sorted out the confusion for me was when someone demonstrated to me how
sys.executable could be fooled:

$ exec -a /usr/bin/foobar python
Python 2.5.1 (r251:54863, May  4 2007, 16:52:23)
[GCC 4.1.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.executable

To remove the cached version, I ran:
$ hash -d python

After which, running "python" invoked a properly named /usr/local/bin/python
as expected.


More information about the Python-list mailing list