From cea1d914003fdac072ac48f87e1a2d06adbc6eb4 Mon Sep 17 00:00:00 2001
From: Zhou Qiankang <wszqkzqk@qq.com>
Date: Wed, 10 Dec 2025 12:30:00 +0800
Subject: [PATCH] fix: update launch script handling for mingw-w64/msys2 on
 Windows

Signed-off-by: Zhou Qiankang <wszqkzqk@qq.com>
---
 setup.py | 35 ++++++++++++++++++++---------------
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/setup.py b/setup.py
index a75045eb..aba651bd 100644
--- a/setup.py
+++ b/setup.py
@@ -508,23 +508,28 @@ class install_pymol(install):
 
         with open(launch_script, "w") as out:
             if WIN:
-                # paths relative to launcher, if possible
-                try:
-                    python_exe = "%~dp0\\" + os.path.relpath(
-                        python_exe, self.install_scripts
-                    )
-                except ValueError:
-                    pass
-                try:
-                    pymol_file = "%~dp0\\" + os.path.relpath(
-                        pymol_file, self.install_scripts
-                    )
-                except ValueError:
-                    pymol_file = os.path.abspath(pymol_file)
-
                 if not self.pymol_path_is_default:
                     out.write(f"set PYMOL_PATH={pymol_path}" + os.linesep)
-                out.write('"%s" "%s"' % (python_exe, pymol_file))
+
+                if is_mingw:
+                    python_exe = "%~dp0\\python.exe"
+                    out.write('"%s" -m pymol' % python_exe)
+                else:
+                    # paths relative to launcher, if possible
+                    try:
+                        python_exe = "%~dp0\\" + os.path.relpath(
+                            python_exe, self.install_scripts
+                        )
+                    except ValueError:
+                        pass
+                    try:
+                        pymol_file = "%~dp0\\" + os.path.relpath(
+                            pymol_file, self.install_scripts
+                        )
+                    except ValueError:
+                        pymol_file = os.path.abspath(pymol_file)
+                    out.write('"%s" "%s"' % (python_exe, pymol_file))
+
                 out.write(" %*" + os.linesep)
             else:
                 out.write("#!/bin/sh" + os.linesep)
-- 
2.50.1.windows.1

