This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Change sys.executable to include executable suffix
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: erik.bray, masamoto, methane, zach.ware
Priority: normal Keywords: needs review, patch

Created on 2016-10-14 13:34 by erik.bray, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
cygwin-sys-executable.patch erik.bray, 2016-10-14 13:34 review
sys-executable-suffix.patch masamoto, 2016-10-18 22:01 review
sys-executable-suffix-2.patch masamoto, 2016-11-03 01:24 review
sys-executable-suffix-3.patch masamoto, 2016-11-29 08:37 review
Pull Requests
URL Status Linked Edit
PR 4348 merged erik.bray, 2017-11-09 14:36
PR 12063 merged miss-islington, 2019-02-27 03:04
Messages (9)
msg278651 - (view) Author: Erik Bray (erik.bray) * (Python triager) Date: 2016-10-14 13:34
This actually came up previously in #1543469 in the context of test_subprocess, but it's a more general issue that I thought was worth addressing somehow.

The issue here is that as Cygwin tries to provide a "UNIX-like" experience, any system interfaces that take the path to an executable as an argument allow the .exe extension to be left off.  This is particularly convenient for the shell experience, so that one can run, for example "python" or "ls" without typing "python.exe"  or "ls.exe" (this is of course true of the Windows cmd shell as well).

In the case of ambiguity however--such as when there is both a "python" and a "python.exe" in the same path, one must explicitly add the ".exe", otherwise the path without the exe is assumed.  This is made even worse when you factor in case-insensitivity.

Thus, this becomes a real annoyance when developing Python on Cygwin because you get both a "python.exe" and the "Python" directory in your source tree.  This isn't so much of a problem, except that sys.executable leaves off the ".exe" (in UNIX-y fashion), so any test that calls Popen([sys.executable]) errors out because it thinks you're trying to execute a directory (Python/).

I think the only reasonable fix is to take the patch suggested at #1543469, and ensure that the ".exe" suffix is appended to sys.executable on Cygwin.  I think that sys.executable should be as unambiguous as possible, and that's the only way to make it reasonably unambiguous on Cygwin.

I've attached a patch adapted from the one in #1543469 which solves the issue for me.
msg278736 - (view) Author: Masayuki Yamamoto (masamoto) * Date: 2016-10-15 21:43
This patch has impact to end user, thus I don't agree to apply as far as Cygwin to avoid user surprise.
I think to need a consistency between other platforms having executable suffix (e.g. MSYS2), and also the patch needs short documentation of changing behavior to description for sys.executable.
msg278799 - (view) Author: Erik Bray (erik.bray) * (Python triager) Date: 2016-10-17 09:11
I agree this has a slight change in behavior which I was at first hesitant about.  But I think the previous behavior was wrong insofar as it was overly ambiguous.  I agree it should apply on MSYS2 as well (I actually thought __CYGWIN__ was defined on MSYS2 but I could be wrong about that).

I'm not sure what better solution there is.  I thought of tinkering with subprocess specifically, but that was too fragile.
msg278943 - (view) Author: Masayuki Yamamoto (masamoto) * Date: 2016-10-18 22:01
I agree to add the suffix to solve ambiguous path on Cygwin. And I think the patch should apply to all platforms having executable suffix.

Therefore, I modified your patch to remove #if directive for Cygwin, and I changed title to spread covered platforms.
This patch uses EXE_SUFFIX that is the EXE defined on Makefile. If platform doesn't have executable suffix, doesn't add anything process.
msg279957 - (view) Author: Masayuki Yamamoto (masamoto) * Date: 2016-11-03 01:24
I have missed a case of empty progpath. I updated the patch to avoid calling add_exe_suffix() at that case.
msg280204 - (view) Author: Erik Bray (erik.bray) * (Python triager) Date: 2016-11-07 15:29
Thanks! Setting EXE_SUFFIX from the Makefile is much better.
msg281969 - (view) Author: Masayuki Yamamoto (masamoto) * Date: 2016-11-29 08:30
I updated a patch to check the made path because previous patch has added suffix even to symbolic link. New patch works that If made path is invalid, revert to original.
msg327126 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2018-10-05 11:38
New changeset 7a7693e9cb12e5571c76331db56a28eef9acb6e0 by INADA Naoki (E. M. Bray) in branch 'master':
bpo-28441: Ensure `.exe` suffix in `sys.executable` on MinGW and Cygwin (GH-4348)
https://github.com/python/cpython/commit/7a7693e9cb12e5571c76331db56a28eef9acb6e0
msg336738 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2019-02-27 09:24
New changeset e5897b67badeb04a04e16e29f7650d833141d67e by Inada Naoki (Miss Islington (bot)) in branch '3.7':
bpo-28441: Ensure `.exe` suffix in `sys.executable` on MinGW and Cygwin (GH-4348)
https://github.com/python/cpython/commit/e5897b67badeb04a04e16e29f7650d833141d67e
History
Date User Action Args
2022-04-11 14:58:38adminsetgithub: 72627
2019-02-27 17:10:20ned.deilysetversions: + Python 3.7
2019-02-27 09:24:47methanesetmessages: + msg336738
2019-02-27 03:04:20miss-islingtonsetpull_requests: + pull_request12087
2018-10-05 11:46:28methanesetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
versions: + Python 3.8, - Python 3.7
2018-10-05 11:38:55methanesetnosy: + methane
messages: + msg327126
2017-11-09 14:36:46erik.braysetpull_requests: + pull_request4305
2016-11-29 08:37:12masamotosetfiles: + sys-executable-suffix-3.patch
2016-11-29 08:34:18masamotosetfiles: - sys-executable-suffix-3.patch
2016-11-29 08:30:21masamotosetfiles: + sys-executable-suffix-3.patch

messages: + msg281969
2016-11-07 15:29:33erik.braysetstage: patch review
2016-11-07 15:29:03erik.braysetmessages: + msg280204
2016-11-03 01:24:05masamotosetfiles: + sys-executable-suffix-2.patch

messages: + msg279957
2016-10-18 22:01:05masamotosetfiles: + sys-executable-suffix.patch

messages: + msg278943
components: + Interpreter Core
title: sys.executable is ambiguous on Cygwin without .exe suffix -> Change sys.executable to include executable suffix
2016-10-17 09:11:53erik.braysetmessages: + msg278799
2016-10-15 21:43:41masamotosetmessages: + msg278736
2016-10-14 13:34:45erik.braycreate