when sys.executable is run with a modified argv[0] such as:
> sh -c "exec -a '' /usr/bin/python2.7 -c 'import sys; print(sys.executable)'"
it returns some a hardcoded value. In this case, it returns /usr/bin/python. This value is likely wrong when python is installed with "make altinstall".
A possible solution is to modify the "progname" variable in Python/pythonrun.c to include the version in it so that the hardcoded return value is the most version specific binary. I.e.
static char *progname = "python2.7";

Another alternative might be to return "None" ("refuse the temptation to guess"). But, given the long standing nature of the current guessing, having it return the specific version string may indeed make sense.

For Python < 3.2, I think adding the version number alone makes sense. Can you think of any situations where the trailing digits could break something?
For Python 3.2 I'd suggest also adding the build flags to sys.executable. If you want the most specific binary, that would make the most sense.

Well, the digits are there if they are there in the name when that's actually what is in argv[0], so as long as that's the name the binary is actually installed under I don't think it will break anything. I presume the same applies to the abi flags but haven't checked.
That said, I don't know for sure that progname is the right thing to change; I haven't looked through the code to see how sys.executable is generated or if there is anything else GetPythonName is used for.
Hmm. I suppose there could be an issue if Python is invoked through a wrapper...I know Gentoo does that, so I've added Arfrever to nosy to see if he has an opinion.

> Garbage in, garbage out.
In this case – exec -a '' – yes, but in general not so – see "Mismatch between sys.executable and sys.version in Python" question at SO (http://stackoverflow.com/q/22236727/95735).
As to not guessing Victor STINNER in comment http://bugs.python.org/issue7774#msg100849 wrote this:
"
There are different methods to get the real program name, but no one is portable. As flox wrote, we can "do a best effort to provide a valid sys.executable". Extract of stackoverflow link:
* Mac OS X: _NSGetExecutablePath() (man 3 dyld)
* Linux: readlink /proc/self/exe
* Solaris: getexecname()
* FreeBSD: sysctl CTL_KERN KERN_PROC KERN_PROC_PATHNAME -1
* BSD with procfs: readlink /proc/curproc/file
* Windows: GetModuleFileName() with hModule = NULL
"