我有一个用Python 2.7和PyGTK编写的项目,用py2exe进行编译。我有两个模块,“Launchpad.py”和“RegistrationScreen.py”。我需要从 Launchpad.py 打开 RegistrationScreen.py。
我当前使用以下代码:
def open_registration(event, data=None):
subprocess.Popen(["python", "RegistrationScreen.py"])
当我测试时,这工作正常 - 窗口在没有打开 shell 窗口的情况下打开。
但是,当我使用 py2exe 进行编译时,在执行创建的应用程序时出现以下日志错误。
Traceback (most recent call last): File "Launchpad.py", line 26, in open_registration File "subprocess.pyc", line 672, in init
File "subprocess.pyc", line 882, in _execute_child WindowsError: [Error 2] The system cannot find the file specified
如何修复我的代码以便 py2exe 能够正确编译它?有没有其他方法可以从 Launchpad.py 打开 RegistrationScreen.py 模块的窗口,而不会在最终的 .exe 文件中引发错误?
最佳答案
问题出在路径上。 RegistrationScreen.py(可能)压缩在 dist/library.zip 中,但是调用它的代码正在 dist/RegestrationScreen.py 中查找它。
我不知道最好的解决方案是什么...... py2exe 访问文件有点痛苦。
此外,您可能不想执行 subprocess.Popen(["python", "RegistrationScreen.py"])
因为您无法保证您的用户将安装 python 并且全系统可访问。如果您确实需要一个单独的进程,那么也许您应该在 RegistrationScreen.py 上单独运行 py2exe 以创建一个单独的 .exe,然后将其包含在主 .exe 的 dist 文件夹中?
我知道这有点复杂,但它可能会起作用。正如我所说,可能有更好的方法。
关于python - 在 py2exe 中打开 PyGTK Python 模块错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7052701/