EDIT: 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.
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?
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
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.
Details:
Python version: 2.7.7 32 bit
Pygame version: 1.9.3 32 bit
PyInstaller version: 1.5 32 bit
System: Windows 8.1 64 bit (the 32 bit programs have all worked fine so far though)
Try to open command prompt and drag exe into it and press enter, that way you will catch the error (if there is any) and then update your question, more info == more help.
I never used pyinstaller so I can't really help you on that.
Also I suggest you to try py2exe, it worked nicely with pygame (at least for me) and later you can make setup with NSIS or Inno.
Edit:
If the .exe can't permanently save the highscores (as you said in comment below) try running exe as admin, it might be just matter of write privileges , or maybe it is your antivirus who doesn't allow it to write (sandbox at Avast, unknown/rare file at Norton).
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.
Related
I have a question for you that is making me crazy.
I am working on my python package. I'm building my package using hatchling and pyproject.toml and I have also three GUI targets.
To make them I'm using the project.gui-scripts section in the project files and indeed, three exe files are included in the scripts directory after the package installation.
All of a sudden two out of three exe files are not starting at all. If you execute it from CMD, you don't get any error message, nothing. I said all of a sudden because in the past they all used to work.
The third one, instead is still working nicely.
Do you know if there is anything I can do to check what's going wrong? Can I debug those exe files?
Thanks in advance,
I created a data-miner GUI for twitter with kivy and am currently having a lot of trouble turning it into an exe. I tried following this video and import glew and sdl2 into my spec but after doing pyinstaller main.spec, my executable still would not open.
Is it because I have more than one files and folders for my program (here is the link to the github repo for my project), if so, how do you deal with that?
In addition, if I manage to success create a working exe, how do I create an exe installer that other people can use to install the executable?
Making an executable from a complex script like yours may become quite frustrating because of its dependencies. But I'm giving you a brief guide about what you need to follow to achieve your goal.
Create your main.spec file with console-mode enabled to see the exact error message for the app. (make sure to remove --noconsole from PyInstaller command or set console=True in spec file). Also use --no-upx in the build command to remove compression from output file (this helps with omitting some DLLs which may cause issues).
You need to make sure that every external module you used can pack correctly. I don't think you get any problem with either Kivy or Tweepy. But if you get any missing import error, try to check the solution for each one by searching the pattern [module] pyinstaller.
Your app has external resources like images, files, etc., which must be added to the packed executable and load properly. I wrote an answer about this here.
If you want a standalone executable, you need to use -F with PyInstaller command, which is more robust than using an installer to gather files in one directory mode.
Hey guys I created a program, used pyinstaller --onedir 'name' and created the exe.
Now I am having an issue while it works perfectly on my computer (windows 7) when I took the dist folder to a windows 10 machine the cmd window started and closed at once without running and without giving out an error message (or it was fast enough that I could not see it).
Is this an issue with windows 10 or did I do anything wrong when compiling to exe?
What happens is that probably your dist directory requires different dlls, probably some system ones that you need to add them into your one directory executable so that everything is linked correctly.
One way to find the missing dependencies of your exe is to use Processor monitor https://learn.microsoft.com/en-us/sysinternals/downloads/procmon in your Win 10. You see the traces of your process and then you investigate.
One other way is to install Process explorer https://learn.microsoft.com/en-us/sysinternals/downloads/process-explorer and check the dlls that did load to see where it stops.
There is also https://dependencywalker.com/ which is really powerful, but when I used it in similar scenarios, it didn't help me that much.
Also have a look at the possible errors that pyinstaller might raise, even the slightest warning can be helpful.
One other concern would be the machine you are using: let's say you have a generated process which contains dlls with 64 bits that you are trying to run in a machine with 32 bits.
I hope this helps.
I have built a Cx Freeze exe from python code. Code worked fine. I recently modified one .py file and rebuilt the exe. Dragged the entire build directory over to another computer for use and it looked as though it was using an older version of the code. Rebuilt, retried. Same thing.
Ended up moving over the new updated python file to the other computer and the exe starts working correctly.
Looks like the exe is not truly independent of the uncompiled code?
Have any of you seen this? Is it a bug? Is there a fix?
thanks!!
I had this same issue and found some troubleshooting steps to fix the problem:
Change the version number in setup.py.
Change the name of the init.py (or whatever your first file is called.) Change the name in setup.py to match.
Copy your files into a separate folder along with the setup.py and rerun there.
I am "compiling" my Python application for Windows with PyInstaller 2.1. I initially tried using onefile mode, but onefile takes a long time to startup (decompressing wx and matplotlib). With the onedir mode it's pretty fast (only a little bit slower than native python).
So I want to use onedir mode for faster startup times, but for the end-user it's difficult to find the actual *.exe file inside the huge amount of files located in the main directory (there are 98 files including the actual executable and it's manifest).
I want to make sure a non tech-savvy user can easily "double-click" the executable and work with this program (ease and portability) without a long disclaimer to "just ignore" the 97 other files there.
Is it possible to move all those "distracting" files into a subfolder? Or are there other ways to make it easy for the end-user to run this program?
maybe you could use onedir. The resulting folder you can put anywhere and create a shortcut to the user where it is more comfortable.
Easiest way to reduce the number of files created in --onedir mode would be to create a virtual environment and install only the necessary modules.
You could use some software to pack it into a one-file installer, such as Inno setup.
You could also try to delete some files one by one (if the executable fails just undelete it). I figured out that almost half of the files can be deleted with the executable working fine.
Download Inno Setup from here.