-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
[Windows] installations should include pythonX.exe and pythonX.Y.exe executables #65705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
A python.org 2.7.6 release of the Windows MSI installer, results in only the following python binaries in the installation directory: In Mozilla bug https://bugzilla.mozilla.org/show_bug.cgi?id=957721 we would like to be able to force our 'mach' script to use Python2.7 (due to the assorted Python versions present on our CI machines), however doing so via the script shebang line breaks local developer workflows on Windows, since the default Python install doesn't include python2.7.exe and so the binary isn't found. As such, it would be great if python.exe could be symlinked to pythonX.Y.exe (and also I guess pythonX.exe) as part of the Windows installation/build - giving us parity with Unix based platforms. This can be done on Windows using mklink (http://ss64.com/nt/mklink.html), eg: c:\Python27>mklink python2.7.exe python.exe c:\Python27>mklink python2.exe python.exe c:\Python27>dir python* 10/11/2013 19:24 26,624 python.exe Alternatively, just a plain copy of the binary prior to creating the MSI would be just as helpful for us too. I searched for a while to see if there were any bugs filed for this already, but the closest I could find was:
Many thanks :-) |
Meant to add: the ActivePython release does this already - but it would be great if upstream did too. |
A similar thought I've had is to add a feature to the PEP-397 launcher, allowing it to figure out Python version from a suffix on its executable name and add symlinks to it for each installed version of Python. That way PATH wouldn't need to be modified to make every installed version accessible from a single optionless command. |
I don't deal with Python 2.7 anymore, so I have no opinion on this matter. |
As far as Python 2.7 is concerned, I will be avoiding making any changes to the installer at all. For Python 3.5 I'm trying to work out a few of the install issues, one of them being not installing into Program Files. I think symlinks may be the way to make that change work, in which case it will be trivial to add two more. That said, I prefer the py.exe launcher anyway (especially since it handles 32/64-bit slightly better than this would), mostly since I intensely dislike permanently modifying PATH for anybody :) |
How about using hard links (mklink /H) instead? It's a minor issue, but there's a bug in Explorer that breaks opening symbolic links to EXE, COM, CMD, and BAT files (exefile, comfile, cmdfile, batfile). Explorer displays the error message "the specified path does not exist". These file types have shell\open\command set to "%1" %*, i.e. the file itself (%1) is used as the command.
I assume that's because these file types can be passed directly to CreateProcess. However, the Explorer bug isn't a problem with CreateProcess, or even ShellExecuteEx. Maybe it's due to an overly strict security policy. Anyway, my 2 cents is use hard links. |
Do you know which versions of Windows this applies to? It works fine for me (though I'm up to date), and the file associations have not changed. I've seen some suggestions that creating a symlink without the right file extension (e.g. python2 <<===>> python.exe rather than python2.exe) will fail in some cases, but that's easily avoided by getting the symlink right. |
Here's a related superuser question:
The message box shown in the older answer is what I get:
The problem is only with Explorer. I can execute a symbolic link to an EXE via cmd, subprocess.Popen, os.startfile (ShellExecute), and so on. Also, Explorer only does this for the executable file types that I mentioned. It has no problem opening symbolic links to .py files; the difference is the open command line for a Python.File includes a program to run:
It works if I change the shell\open\command for the exefile type to run via cmd /c. But that's just silly. |
Apparently there's a distinction between absolute and relative symlinks. Do you see a difference between:
and
? |
Using a relative target in the link isn't the problem for me here. (See bpo-13702 for another problem with relative links.) I'm in the same boat as commenter weberc2. Same symptom; apparently a different problem. I'm using an absolute path for the target: C:\Program Files\Python\Scripts>mklink python2.7.exe "C:\Program Files\Python\Python27\python.exe" (Mirror the --user layout in %AppData%.) This works fine from cmd, but not Explorer. Anyway, the link would be added to support shell scripts that use shebangs for environments such as MSYS, so executing with Explorer isn't the goal anyway. The shortcut in the start menu would target python.exe, not the symbolic/hard link. |
I've changed the version to 3.6 only as I just can't see this happening for any other. For all I know this might have been sorted in 3.5, I'll leave that decision to our Windows gurus. |
Creating a symbolic link can't be relied on for a per-user installation. Administrators have to elevate to create symbolic links, and most regular users also lack this privilege. |
The file is so small that a second copy is just as cheap - literally everything is in the DLL. It could certainly be added to 3.6, and I'll probably get to it eventually, but right now I'm still focused on 3.5. |
One issues with versioned "X.Y" executables is interference with normal handling of the ".exe" extension. For example, in "python3.10" the ".10" counts as an extension, so normally ".exe" won't be appended when searching for the name. This affects SearchPathW() searches that supply a default ".exe" extension, such as what CreateProcessW() uses to find the executable parsed from lpCommandLine. For example, subprocess.call('python3.9') won't append '.exe' to find "python3.9.exe" in the search path. It also affects the shell API's "App Paths" search, since the shell won't append ".exe" to a name that already has an extension. (The machine and user "App Paths" keys are the Windows shell equivalent of Unix "/usr/bin" and "$HOME/.local/bin", but more powerful.) For example, the store app distribution of Python 3.9 creates a "python3.9.exe" entry in the user's "App Paths", but os.startfile('python3.9') doesn't work; it has to be os.startfile('python3.9.exe'). Using "_" instead of "." would be compatible with Windows filename conventions -- e.g. "python3_10.exe". But this is an uphill battle against a Unix convention that's probably been in use since the 1970s or 1980s. |
Can I confirm that this is still a valid workaround today with [1] Aside from any permissions required, e.g. creating symbolic links, or other programs assuming it's a binary called |
Yep. As I've mentioned elsewhere, nothing much has changed here. In a virtual environment, you'll need to copy the |
#99185 is a newer version of this bug, so I'd rather close this and keep that one open. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: