Windows-Pyinstaller 错误“无法执行脚本"当应用程序被点击时 [英] Windows- Pyinstaller Error "failed to execute script " When App Clicked
问题描述
我很难克服这个错误,我到处搜索该错误消息,但似乎没有任何与我的情况相关的内容:
I am having a tough time overcoming this error, I have searched everywhere for that error message and nothing seems relevant to my situation:
"failed to execute script new-app"
new-app 是我的 Python GUI 程序.当我使用以下命令运行 pyinstaller 时:
new-app is my python GUI program. When I run pyinstaller using this command:
pyinstaller.exe --onedir --hidden-import FileDialog --windowed --noupx new-app.py
它运行起来很顺利.另外,当我执行命令行运行gui程序时,完美运行,使用这个命令生成GUI:
It does work smoothly. In addition, when I execute the command line to run the gui program, it works perfectly and the GUI is generated using this command:
.dist
ew-app
ew-app.exe
但是当我去那个文件希望能够点击应用程序来获取 GUI 时,它给了我上面说的错误.这是为什么?
But when I go to that file hopefully to be able to click the app to get the GUI, it gives me the error said above. Why is that?
我使用的是 python2.7,操作系统是 Windows 7 Enterprise.
I am using python2.7 and the OS is Windows 7 Enterprise.
任何输入将不胜感激,并在此先感谢.
Any inputs will be appreciated and thanks a lot in advance.
推荐答案
好吧,我想我已经找到了自己问题的解决方案,我是这样做的:
Well I guess I have found the solution for my own question, here is how I did it:
尽管我能够使用普通的 python 命令成功运行该程序以及成功运行 pyinstaller 并能够执行应用程序new_app.exe"使用问题中提到的命令行,在这两种情况下都可以毫无问题地显示 GUI.但是,只有当我单击该应用程序时,它才会允许显示 GUI 并且不会生成错误.
Eventhough I was being able to successfully run the program using normal python command as well as successfully run pyinstaller and be able to execute the app "new_app.exe" using the command line mentioned in the question which in both cases display the GUI with no problem at all. However, only when I click the application it won't allow to display the GUI and no error is generated.
所以,我所做的是在 pyinstaller 命令中添加了一个额外的参数 --debug 并删除了 --windowed 参数,以便我可以看到单击应用程序时实际发生的情况,但我发现有错误当我追踪它时,这很有意义,它基本上抱怨 "some_image.jpg"没有这样的文件或目录.
So, What I did is I added an extra parameter --debug in the pyinstaller command and removing the --windowed parameter so that I can see what is actually happening when the app is clicked and I found out there was an error which made a lot of sense when I trace it, it basically complained that "some_image.jpg" no such file or directory.
当我从一开始运行脚本甚至使用命令行./"时,它会抱怨并且没有抱怨的原因;是因为文件图像与定位的脚本存在于相同的路径中,但是当 pyinstaller 创建dist"时包含应用程序产品的目录很完美,图像文件不存在,所以我基本上将它移动到可点击应用程序所在的 dist 目录!
The reason why it complains and didn't complain when I ran the script from the first place or even using the command line "./" is because the file image existed in the same path as the script located but when pyinstaller created "dist" directory which has the app product it makes a perfect sense that the image file is not there and so I basically moved it to that dist directory where the clickable app is there!
所以简单的答案是将代码使用的所有媒体文件或文件夹放在 exe 文件所在的目录中.
第二种方法是在 pyinstaller 命令中添加--add-data
这篇关于Windows-Pyinstaller 错误“无法执行脚本"当应用程序被点击时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!