PyInstaller .exe file does nothing

此生再无相见时 提交于 2021-02-07 06:24:14

问题


After 3 days, I can't get a python program packaged into a .exe file. I've tried py2exe (which continuously missed modules), and PyInstaller.

Here's the complicated part. My program uses a lot of additional installed modules (coopr, pyomo, openpyxl, glpk, cbc, pyutilib, numpy, etc.). These in turn import all kinds of other things, and I can't track it down (the PyInstaller warning log lists 676 lines of missing or potentially unneeded modules.)

However, I've gotten (by adding imports of "missing" modules to my program) a .exe version which runs from double clicking or from the command line, without printing any error.

The problem is, the program does nothing. I have an input file which is included in the build, which my program reads in, does some (intense) calculations, and then creates a .csv output file in the same directory. It works as a .py file. My .exe does nothing.

So, if you can tell me what's wrong go ahead. If not, I'd like to know any helpful steps or ideas to try. At this point, I've exhausted the feedback I can find from the program and documentation.


回答1:


I just solved this problem for myself.

Make sure you do not have a folder with the same name as the script you are trying to turn into an executable.




回答2:


When creating the exe, make sure that the python script contains

if __name__ == '__main__':
    main()

at the bottom. Otherwise, the python exe will run but since it has nothing to run it will just end.




回答3:


Almost a year and no solution. I imagine you've moved on from this issue at this point, but now I'm having this same issue. I'm using PyInstaller with --onefile option.

Did you try using --noupx? That somehow fixed the issue I was having with the first script I tried compiling. Unfortunately, that was the only script that trick worked on - compiling other .py scripts with pyinstaller using --noupx (with and without the --onefile option) again produced .exe files that don't do anything.




回答4:


I also could not make work pyinstaller properly, but a few years ago I found a solution to generate R scripts executables on windows, so I tried it with python and it worked!

Here is the solution, just in 3 lines in the CMD:

https://github.com/jorgeavilacartes/making-my-own-executable-python

You can create your own extension and assing it to the python.exe you wish (if you have many venv you can create one executable extension for each one)

Unfortunately, I only have the solution for windows.

Hope it helps!

PD: Be careful to do not have any .ipynb in the same folder where you will create your executable, it will not run properly, I do not know why, but it was the only problem I had.




回答5:


If your script accesses non-Python files, move the executable so it can find them.

I was having the same problem. For me, the cause was that some of my Python files required access to non-Python files (in my case, gifs). PyInstaller didn't bundle up the resources along with the Python files and didn't stick the executable in the same directory as the main Python file, so I was getting an error when my program tried to access them. The solution was simply to copy the resources to the location where the executable was looking for them, or vise-versa.

For some reason, the error messages that helped me find the problem didn't generate when I ran PyInstaller normally. They were only generated when using the --onefile flag, and even then, they only stuck around for less than half of a second before the prompt closed. I had to use ctrl+prt to capture my screen when the messages appeared.



来源:https://stackoverflow.com/questions/32592827/pyinstaller-exe-file-does-nothing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!