[Python-Dev] towards a stricter definition of sys.executable

Fredrik Lundh fredrik at pythonware.com
Thu Mar 16 17:12:42 CET 2006

Guido van Rossum wrote:

> For finding related files, sys.exec_prefix and sys.prefix should be used

except that they're defined in terms of where the standard library is:

    prefix -- prefix used to find the Python library
    exec_prefix -- prefix used to find the machine-specific Python library

there are scenarios (e.g. with exemaker) where several applications
share a Python library / Python DLL, but there's no python.exe in sight.

> When Python is embedded in another app (e.g. mod_python), I would
> expect sys.executable to be meaningless and its use to be undefined.
> None would be a good value in that case. sys.prefix / exec_prefix may
> or may not have a useful meaning in such an environment, depending on
> how the standard library is made accessible.
> Can you say more about the motivation for wanting this reinterpreted?

well, I'm not asking for a reinterpretation as much as a clarification, and
possibly some implementation tweaks (since the current code implements
approach (a) by default).

how about this alternative ?  (extended (b)).

    d) If Python was started from a standard Python interpreter,
    sys.executable contains the full path to this interpreter.  If not,
    or if the path could not be determined, sys.executable is set to

    If Python is embedded in another environment, that environment
    may set the executable to a corresponding interpreter, or leave
    it set to None.

    An embedding application may set sys.app_executable to point
    to the application executable.

_PySys_Init should probably be modified to set sys.executable to
None instead of Py_GetProgramFullPath(); the latter should be done
in Py_Main (or in main() ?)

when running under a standard interpreter, sys.app_executable
could be left undefined, set to None, or set to the same thing as
sys.executable.  leaving it undefined is good enough for me.


More information about the Python-Dev mailing list