在 py2exe 中打开 PyGTK Python 模块错误
我有一个用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 进行编译时,在执行创建的应用程序时出现以下日志错误。
回溯(最近一次调用):文件“Launchpad.py”,第 26 行,位于 open_registration 文件“subprocess.pyc”,第 672 行,位于 init
文件“subprocess.pyc”,第 882 行,在 _execute_child WindowsError: [错误2]系统找不到指定的文件
如何修复我的代码以便 py2exe 能够正确编译它?有没有其他方法可以从 Launchpad.py 打开 RegistrationScreen.py 模块的窗口,而不会在最终的 .exe 文件中引发错误?
I have a project written in Python 2.7 and PyGTK, with py2exe for compiling. I have two modules, "Launchpad.py" and "RegistrationScreen.py". I need to open RegistrationScreen.py from Launchpad.py.
I am using the following code currently:
def open_registration(event, data=None):
subprocess.Popen(["python", "RegistrationScreen.py"])
This works fine when I test - the window is opened without the shell window opening.
However, when I compile using py2exe, I get the following log error on executing the created application.
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
How do I fix my code so py2exe will compile it correctly? Is there another way I can open the RegistrationScreen.py module's window from Launchpad.py, that won't throw errors in the final .exe file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是路径。 RegistrationScreen.py(可能)压缩在 dist/library.zip 中,但是调用它的代码正在 dist/RegestrationScreen.py 中查找它。
我不知道最好的解决方案是什么...... py2exe 访问文件有点痛苦。
另外,您可能不想执行
subprocess.Popen(["python", "RegistrationScreen.py"])
因为您无法保证您的用户将安装 python 并且可以在系统范围内访问。如果您确实需要一个单独的进程,那么也许您应该在 RegistrationScreen.py 上单独运行 py2exe 以创建一个单独的 .exe,然后将其包含在主 .exe 的 dist 文件夹中?我知道这有点复杂,但它可能会起作用。正如我所说,可能有更好的方法。
The problem is the path. RegistrationScreen.py is (probably) compressed inside dist/library.zip, but your code that calls it is looking for it in dist/RegestrationScreen.py.
I don't know what the best solution to this is... py2exe is kind of a pain for accessing files.
Also, you probably don't want to be doing
subprocess.Popen(["python", "RegistrationScreen.py"])
because you can't guarantee your users will have python installed and accessible systemwide. If you really need a separate process, then maybe you should run py2exe on RegistrationScreen.py individually to create a separate .exe, and then include that in the dist folder of your main .exe?I know that's somewhat convoluted, but it would probably work. And as I said, there might be a better way.