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.

Title: bdist_wininst-created installer does not run the postinstallation script when uninstalling
Type: behavior Stage: resolved
Components: Distutils Versions: Python 3.6, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 2.7
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: tarek Nosy List: Pierre.Raybaut, eric.araujo, francisco, jasonjroberts, jed.ludlow, loewis, mhammond, petri, tarek, techtonik, vstinner
Priority: normal Keywords:

Created on 2011-10-27 15:30 by francisco, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit francisco, 2011-10-27 15:30 Simple file to reproduce the bug. It includes the Windows installer.
Messages (9)
msg146492 - (view) Author: francisco (francisco) Date: 2011-10-27 15:30
The bug can be reproduced by running the following command to create a Windows installer for the attached module:

python bdist_wininst --install-script

I include also the installer that I have created in the dist folder.

The installer installs everything correctly and it runs the script, which simply creates a file in the USERPROFILE directory with the "Installing" string. However, when uninstalling the program from the Windows Control Panel the script is not called, what can be verified by checking that the "Uninstalling" string is not appended to the file.

I am experiencing this problem in Windows 7 64 bits, but it may be present in other platforms.
msg148674 - (view) Author: Jason Roberts (jasonjroberts) Date: 2011-11-30 16:54
Sorry, I opened issue13509 after somehow not finding this one. Here is my text from issue13509. Thanks for looking at this problem...

Historically (i.e. Python 2.6.1 and earlier) bdist_wininst would run the post install script at both installation and uninstallation. The script would be invoked with a -install argument on installation and a -remove argument on uninstallation. This stopped working in Python 2.6.2 and has not worked since.

This regression appears to have been introduced in r69094. That checkin rewrote Run_RemoveScript and associated functions in PC/bdist_wininst/install.c. The rewrite changed how the Python DLL was loaded during the remove scenario.

Previously Run_RemoveScript itself called Win32 LoadLibrary on the DLL name parsed from the wininst log file. Now Run_RemoveScript calls run_installscript instead, which ultimately calls LoadPythonDll, which calls LoadLibrary on the pythondll global variable. But nothing initializes that variable during the remove scenario and LoadLibrary fails. Ultimately run_installscript silently fails and the removal proceeds to uninstall files and registry keys, with no notification to the user that the post install script was not run.

A possible solution is to initialize pythondll in Run_RemoveScript to the DLL name parsed from the wininst log file, e.g. by inserting the following code prior to the call to run_installscript:

        strncpy(pythondll, dllname, scriptname - 1 - dllname);
        pythondll[scriptname - 1 - dllname] = '\0';

I tested this and it seemed to work fine.

I believe this problem affects all Python releases following and including 2.6.2. The version history seems to show that r69094 was propagated to all of those releases. Presumably nobody found it because post install scripts on removal are not widely used. They are, however, critical for my application (at least if I want it to clean up properly on removal) so I would appreciate this being fixed. As it stands, I have to build a private patched copy of wininst-9.0.exe to work around this problem.
msg148676 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-11-30 17:17
(2.6 and 3.1 don’t get bug fixes anymore.)
msg184523 - (view) Author: Pierre Raybaut (Pierre.Raybaut) Date: 2013-03-18 21:16
How can I help to ensure that the patch submitted by Jason Roberts is actually taken into account in next releases of Python?

I too would want to use this "remove" feature in distutils Windows installers. For example, I was confronted to this bug/limitation of current releases of Python when implementing this feature for the Spyder Windows installer:

Thanks for taking time to fix this issue.
msg186522 - (view) Author: Jed Ludlow (jed.ludlow) Date: 2013-04-10 17:34
I can confirm that the approach suggested in msg148674 resolves this issue for Python 2.7.3 (32-bit Python running on 64-bit Windows 7). For a standard 2.7.3 install, simply replacing wininst-9.0.exe in the command sub-directory of distutils with the patched build of that executable resolved the issue.
msg191734 - (view) Author: anatoly techtonik (techtonik) Date: 2013-06-23 21:51
@Pierre.Raybaut: Looking at the stage of this ticker, I believe you need to write unittest. Then attach a patch. If patch is attached, the issue is more visible among developers.
msg202567 - (view) Author: anatoly techtonik (techtonik) Date: 2013-11-10 20:21
Here is workaround, which is - patching distutils -
msg260366 - (view) Author: francisco (francisco) Date: 2016-02-16 18:19
I believe that this bug—which I reported in 2011—is not correctly tagged, what may explain why it has not been fixed yet. Despite the fact that the original issue report contains a script to reproduce the bug and that  msg148674 contains a patch to fix the issue the State of this issue is "test needed". Shouldn't State be "patch review" instead?
msg384819 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-01-11 12:51
The distutils bdist_wininst command has been removed in Python 3.10: see bpo-42802.
Date User Action Args
2022-04-11 14:57:23adminsetgithub: 57485
2021-01-11 12:51:21vstinnersetstatus: open -> closed

nosy: + vstinner
messages: + msg384819

resolution: wont fix
stage: test needed -> resolved
2016-09-21 04:39:00petrisetnosy: + petri
2016-02-16 18:19:16franciscosettype: behavior
messages: + msg260366
versions: + Python 3.6
2013-11-11 02:22:11brian.curtinsetnosy: - brian.curtin
2013-11-10 20:21:35techtoniksetmessages: + msg202567
versions: + Python 3.4, Python 3.5
2013-06-23 21:51:02techtoniksetmessages: + msg191734
2013-06-23 21:48:58techtoniksetnosy: + techtonik
2013-04-10 17:34:46jed.ludlowsetnosy: + jed.ludlow
messages: + msg186522
2013-03-18 21:16:35Pierre.Raybautsetnosy: + Pierre.Raybaut
messages: + msg184523
2011-11-30 17:17:17eric.araujosettitle: distutils bdist_wininst created installer does not run the postinstallation script on uninstalling -> bdist_wininst-created installer does not run the postinstallation script when uninstalling
messages: + msg148676
versions: - Python 2.6, Python 3.1
2011-11-30 16:54:07jasonjrobertssetmessages: + msg148674
versions: + Python 2.6, Python 3.1
2011-11-30 16:48:08eric.araujolinkissue13509 superseder
2011-11-30 16:48:01eric.araujosetnosy: + jasonjroberts, brian.curtin
stage: test needed

versions: + Python 3.2, Python 3.3
2011-10-27 15:36:30eric.araujosetnosy: + loewis, mhammond
2011-10-27 15:30:55franciscocreate