Author eryksun
Recipients Arfrever, allan, barry, eric.araujo, eryksun, iritkatriel, loewis, ncoghlan, piotr.dobrogost, r.david.murray, stephane
Date 2021-08-07.17:33:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1628357586.48.0.505399593874.issue10835@roundup.psfhosted.org>
In-reply-to
Content
In 3.2, the default program name on non-Windows systems was changed to "python3" (see bpo-15020). In 3.5, the code was moved into Python/pylifecycle.c (see bpo-22869). Between 3.7 and 3.8, the initialization code was rewritten (see PEP 587). Currently it's set in config_init_program_name() in Python/initconfig.c. On POSIX systems, calculate_which() in Modules/getpath.c searches PATH to resolve the name if it has no path separator. For example:

    $ bash -c 'exec -a "" python -c "import sys; print(repr(sys.executable))"'
    '/home/someone/.local/bin/python3'

The default "python3" program name isn't used if C argv[0] is non-empty, in which case calculate_which() may or may not find the given program name:

    $ bash -c 'exec -a "ls" python -c "import sys; print(repr(sys.executable))"'
    '/usr/bin/ls'

    $ bash -c 'exec -a "py" python -c "import sys; print(repr(sys.executable))"'
    ''

In Windows, the default program name is "python", but this isn't relevant for sys.executable, which is based on GetModuleFileNameW(NULL, ...) instead. This is similar to using readlink("/proc/self/exe", ...) in Linux, except the loader in Windows, and thus GetModuleFileNameW(), does not resolve symlinks in the file path.
History
Date User Action Args
2021-08-07 17:33:06eryksunsetrecipients: + eryksun, loewis, barry, ncoghlan, eric.araujo, Arfrever, r.david.murray, allan, stephane, piotr.dobrogost, iritkatriel
2021-08-07 17:33:06eryksunsetmessageid: <1628357586.48.0.505399593874.issue10835@roundup.psfhosted.org>
2021-08-07 17:33:06eryksunlinkissue10835 messages
2021-08-07 17:33:06eryksuncreate