[issue44934] Windows installer: Append Python to PATH instead of prepending it
New submission from Bastian Neuburger : Hi there, in our organization Python 3.9 is installed on Windows with the PrependPath option; as expected the Install and Scripts directories are prepended to path. However if there are Python scripts with the same name as a system command (e.g. a script named ping.py vs. the included ping.exe), the Python script gets preferred if I run ping in cmd.exe or Powershell, which makes sense, since the Python script path is considered before e.g. C:\Windows\System32\. Is it possible to either change the option to append the Install and scripts directories to the systems PATH instead of prepending it or add an AppendPath option? I searched for a discussion why prepending was chosen instead of appending but I didn't find anything. -- components: Windows messages: 399737 nosy: bn_append, paul.moore, steve.dower, tim.golden, zach.ware priority: normal severity: normal status: open title: Windows installer: Append Python to PATH instead of prepending it type: behavior versions: Python 3.9 ___ Python tracker <https://bugs.python.org/issue44934> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44934] Windows installer: Append Python to PATH instead of prepending it
Bastian Neuburger added the comment: Hi Steve, Of course there are various reasons for having multiple Python versions on a developer workstation but I would assume that the majority of Windows installer users simple want to run Python projects, at least this holds true for the majority of Python on Windows users in my org. > if you'd really like this to be in the installer, feel free to go for it. could you point me to the relevant files and lines for the PrependPath CLI option and implementation logic on Github? Not sure if I got it right, but I assume the following file is in charge of modifying the env:path: https://github.com/python/cpython/blob/main/Tools/msi/path/path.wxs Since I have never worked within the MSI framework, I could not figure out how the "call flow" from enabling the definition of the PrependPath in https://github.com/python/cpython/blob/main/Tools/msi/bundle/bundle.wxs to actually modifying the path Regarging path.wxs: Would you prefer that I add a pathappend/pathappend.wxs or should I simply add a new Component ID like so: ALLUSERS=1 ... Or would I introduce a new condition ALLUSERS_APPEND or something? -- ___ Python tracker <https://bugs.python.org/issue44934> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44934] Windows installer: Append Python to PATH instead of prepending it
Bastian Neuburger added the comment: Thanks for the rundown, after digging a little bit into the abyss that is the WIX toolset if you've never dealt with it before I already started going down that route. I pushed it to my fork of cpython: https://github.com/bneuburg/cpython/commits/issue44934 Since I'm pretty sure that my commits are not correct yet (following the instructions in Tools/msi/README.txt regarding fetching dependencies building the MSI resulted in a failed build before I even touched a single line of code) I abstained from handing in a pull request. Feedback would be very much appreciated. Of course if you'd want to use that stuff and refine it I would be totally fine with it ;) In case I messed up any formal requirements (i.e. wording of commit messages etc.): I will get myself up to speed and fix that, but since I'll be offline for a week starting Monday I wanted to get my initial draft out there, so in case you have any feedback until Monday I can incorporate it before my brain pushes that stuff out... -- ___ Python tracker <https://bugs.python.org/issue44934> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44934] Windows installer: Append Python to PATH instead of prepending it
Bastian Neuburger added the comment: Maybe this view better shows what I've actually done: https://github.com/python/cpython/compare/16b9be4861e007ad483611ba0479feb2b90ea783...bneuburg:issue44934?expand=1 -- ___ Python tracker <https://bugs.python.org/issue44934> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44934] Windows installer: Append Python to PATH instead of prepending it
Bastian Neuburger added the comment: Previous URL got "fixed" by roundup, hopefully this one works: https://github.com/python/cpython/compare/16b9be4861e007ad483611ba0479feb2b90ea783...bneuburg:issue44934 -- ___ Python tracker <https://bugs.python.org/issue44934> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44934] Windows installer: Append Python to PATH instead of prepending it
Change by Bastian Neuburger : -- keywords: +patch pull_requests: +26343 stage: needs patch -> patch review pull_request: https://github.com/python/cpython/pull/27889 ___ Python tracker <https://bugs.python.org/issue44934> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44934] Windows installer: Append Python to PATH instead of prepending it
Bastian Neuburger added the comment: Steve, I signed the CLA and created the PR, I don't know how long it takes until the info that the CLA is signed is propagated to bpo or github. Regarding failed builds: I will try to build again tomorrow when back at the office and can copy the errors, how would you like to receive them? For building I spun up a MS Windows 10 Edge Test VM, installed Visual Studio 2019 and then tried to run get_externals.bat; that already failed since the nuget config was empty and thus had no upstreams configured. Maybe this problem stems from the free test VM. After editing the nuget config, that script worked out fine and then I run build.bat, which seemed to be quite busy for at least 10 minutes, then I left my office. Upon return I saw plenty of errors. -- ___ Python tracker <https://bugs.python.org/issue44934> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44934] Windows installer: Append Python to PATH instead of prepending it
Bastian Neuburger added the comment: Attached is the full output of: - msbuild.exe -version - get_externals.bat - build.bat For the first few build tasks there are git related errors, which make sense since I ran the build from a downloaded zip release of the source instead of a git clone. I assume the first "real" error occurs when building the wix targets, just grep for MSB4062, this is when things go downhill. -- Added file: https://bugs.python.org/file50231/buildout.txt ___ Python tracker <https://bugs.python.org/issue44934> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44934] Windows installer: Append Python to PATH instead of prepending it
Bastian Neuburger added the comment: Ah ok. Do you know if VS 2019 will do the job at all? I encountered a few (unrelated) projects on github that state they will only build with VS 2017. I will install .NET 3.5 via the VS 2019 installer (should do the trick, right?) and see how it turns out. Could you attach the msi installer build artifact from the build you kicked off so I can test if the appendpath stuff works as expected? Or did you already have a look at it? P.S.: bpo now recognizes that I signed the CLA, github not yet. -- ___ Python tracker <https://bugs.python.org/issue44934> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue44934] Windows installer: Append Python to PATH instead of prepending it
Bastian Neuburger added the comment: Update: .NET 3.5 installation worked out fine via VS 2019 installer, I also added the VS2017 build tools as a precaution since the VM builds take some time. Afterwards build.bat still failed during wix steps, complaining about missing python.exe in PCBuild/win32, not sure if the 32bit interpreter should be fetched/built automagically. Then I tried build.bat -x64, which ran succesfully and provided attached installer. To test it (in administrative shell): 1. git clone https://github.com/bneuburg/python_msi_appendpath 2. cd python_appendpath_installer 3. .\python-3.11.0.7539-amd64.exe /quiet InstallAllUsers=1 AppendPath=1 Include_test=0 Running this in an administrative shell appended InstallDir and Installdir/Scripts to the sytem PATH and created the PATHEXT entries for PY and PYC as well. So far so good! I only noticed the following problem: The first uninstall also succesfully removed all environment variables, however after reinstalling and re-uninstalling, only the PATHEXT were removed, the Python entries in PATH were not removed. This was also independent of the order of software removal (Python Launcher first or second). Thus I had a look at it with orca.exe [1]: 1. Install with appendpath=1 2. Get list of installed msis with: wmic product get /format:csv > software.csv 3. Search for appendpath in software.csv which will return the location of the msi somewhere in c:\windows\installer 4. Right click that file and select 'Edit with Orca' In the environment table it has entries in the following form for a Local Machine install (c.f. for attached screenshot): Environment | Name| Value | Component PATH_LM | =-*PATH | [~]:[InstallDirectory] | AppendPath_LM which according to Microsoft documentation [2] seems to be as intended (add on install, remove on uninstall). But it just doesn't, also see Sascha's comment above. When looking at Orca I also noticed that I forgot to change the position of InstallDirectory in PATH for the CU install from first to last, I updated the PR accordingly. Since you have a Microsoft e-mail address: Any chances you could ask the MSI pros there what is going on? I'll be busy with offline stuff for a few weeks, but if you have any ideas how to troubleshoot this, let me know. I found a discussion where the order of the prefixes for names was slightly changed [3], i.e. *=- instead of =-* but I don't know if this matters at all or how to test it. Sorry for the text book, things like that really keep me digging. [1] https://docs.microsoft.com/de-de/windows/win32/msi/orca-exe [2] https://docs.microsoft.com/en-us/windows/win32/msi/environment-table [3] https://www.itninja.com/question/add-to-path-envronment-variable -- Added file: https://bugs.python.org/file50233/orca.png ___ Python tracker <https://bugs.python.org/issue44934> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com