首页 > 解决方案 > 有没有办法在 Windows 上使用 32 位 python 2.7 从线程打开 64 位 exe?

问题描述

我有一个在 32 位 python 2.7 中构建的 tkinter UI,我制作了一个按钮,我最终希望在不中断 UI 的情况下打开外部应用程序(64 位 exe 文件)。我的按钮启动一个线程,该线程又启动一个带有新控制台窗口的子进程并调用我的 exe 文件的完整路径。如果我将此完整路径输入到 python 脚本之外的 cmd 窗口中,我的应用程序将成功打开。

我收到错误:WindowsError: [错误 193] %1 不是有效的 Win32 应用程序

我知道这需要运行 64 位版本的 python,或者我的应用程序的 32 位版本。但是,是否有替代解决方案可以通过代码解决,而不是更改我的 python 版本或应用程序?为简单起见,我在下面包含了一些示例代码。

谢谢您的帮助!!

self.VMD_button = tk.Button(self, text="Launch VMD", command=self.show_VMD)

def show_VMD(self):
     VMD_cmd = '"%s"' % "C:\VMD.exe"
     thread= Thread(target=self.call_subprocess, args=[VMD_cmd])
     thread.daemon = True
     thread.start()

def call_subprocess(self, cmd):
     proc = subprocess.Popen(cmd, creationflags=subprocess.CREATE_NEW_CONSOLE).wait()

标签: pythonmultithreadingpython-2.7subprocess32bit-64bit

解决方案


据我所知,答案是“不”。而且,发生的事情就是你刚刚得到的。您的应用程序是 32 位的,因此它只知道 32 位应用程序。它可能无法启动 64 位进程。相反的情况起作用,因为存在向后(但不是向前)兼容性。


推荐阅读