PyInstaller .exe 文件不起作用 [英] PyInstaller .exe file not working

查看:100
本文介绍了PyInstaller .exe 文件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现错误是无法打开资源.将目录复制到 .exe 所在的文件夹中并没有修复它.我尝试从 .spec 文件中删除资源,.exe 文件的大小现在是 9 MB,而不是 52 MB,所以我很确定这些资源已包含在内,但不知何故它们似乎无法被.EXE文件.如果出现任何问题,这是我的 .spec 文件 - 我只修改了 Tree 内容以包含资源, .exe 文件名和图标.

I found out that the error is that the resources couldn't be opened. Copying the directory into the folder where the .exe is didn't fix it. I tried removing the resources from the .spec file and the size of the .exe file is now 9 MB as opposed to 52 MB so I'm pretty sure the resources are included, but somehow they can't seem to be opened by the .exe. In case anything is wrong with it, This is my .spec file - I only modified the Tree thing to include the resources, the .exe filename and icon.

换句话说,现在的问题是:为什么 exe 找不到我的游戏资源,我该怎么做才能解决这个问题?另外,我意识到我的资源文件夹有两个子文件夹 - 这是否意味着我必须以不同的方式编写树?

In other words, the question now is: Why can't the exe find my game resources, and what do I have to do to fix that? Also, I realised my resources folder has two subfolders - does that mean I have to go about writing the Tree differently?

我用 Python 制作了一个游戏(也使用 Pygame),并且想要制作一个可执行文件以便我可以分发它.PyInstaller 似乎非常适合这个,最终,经过一段时间的搜索,我找到了如何让它在 本指南中工作.在我调整代码以使第 2 步工作后,我创建了 .spec 文件,向其中添加了包含资源的目录(如第 5 步,并包括字体文件),将其复制到 .spec 文件所在的同一文件夹中最后我跑了

I've made a game in Python (using Pygame, too) and want to make a single executable file so I can distribute it. PyInstaller seemed perfect for that, and eventually, after a while of searching, I found out how to get it working in this guide. After I tweaked my code to get step 2 working I created the .spec file, added the directory with the resources to it (as in step 5, and including the font file), copied it to the same folder the .spec file was in and finally I ran

build.py game.spec

然后我在它应该在的地方找到了 .exe 文件.但是,当我打开它时,它会在几秒钟后再次关闭,而且我认为就在主菜单出现之前.我不太确定这是字体再次搞砸了,因为我确保将它也包含在资源中...

and I found the .exe file exactly where it was supposed to be. However, when I open it, it just closes again after a few seconds, and I think it's just before the main menu shows up. I'm not really sure it's a font screw-up again though because I made sure to include it in the resources as well...

不幸的是,在网络上搜索解决方案对我没有任何帮助,特别是因为现在有一半指向该项目的链接已损坏.

Unfortunately, searching for a solution on the web didn't help me at all, especially because half the links to the project are broken now.

如果有人知道这里出了什么问题(或需要更多详细信息),请告诉我.

If anyone knows what's gone wrong here (or needs more details) please let me know.

详情:

Python 版本:2.7.7 32 位

Python version: 2.7.7 32 bit

Pygame 版本:1.9.3 32 位

Pygame version: 1.9.3 32 bit

PyInstaller 版本:1.5 32 位

PyInstaller version: 1.5 32 bit

系统:Windows 8.1 64 位(目前 32 位程序都运行良好)

System: Windows 8.1 64 bit (the 32 bit programs have all worked fine so far though)

推荐答案

我没有发现问题是什么,但我设法让它正常工作.我首先使用 pip 安装较新版本的 PyInstaller (2.1) 并再次完成相同的步骤,但这次在 Scripts 目录中运行 pyi-makespec 和 pyi-build 而不是 makespec.py 和 build.py 因为这就是新版本有效,我猜.起初它仍然会抱怨资源丢失,除非我从 cmd 运行它,但我认为这实际上是因为我忘记了第 5 步(makespec 文件中的树).出于某种原因,现在 .exe 无法永久保存高分,但除此之外,它运行良好.

I didn't find out what the problem was but I did manage to get it working. I started by installing the newer version of PyInstaller (2.1) with pip and completing the same steps again, but this time in the Scripts directory and running pyi-makespec and pyi-build instead of makespec.py and build.py because that's how the new version works, I guess. At first it would still complain about the resources being missing unless I ran it from cmd, but I think that was actually because I forgot step 5 (Tree in the makespec file). For some reason now the .exe can't permanently save the highscores, but apart from that it's working perfectly.

这篇关于PyInstaller .exe 文件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆