PyInstaller .exe file does nothing

13,259

Solution 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.

If you already have application file sample.py as well as folder sample (that contains your other .py files, say) and you want the application to retain the name sample, you can work around this problem by renaming sample.py to sample_app.py and then invoke pyinstaller with the --name option e.g., pyinstaller --onefile --name sample sample_app.py The binary created by pyinstaller will be called sample.

Solution 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.

Solution 3

When an exe fails to run when double-clicked in windows, the associated window also automatically closes. If this happens for you, open the command prompt and try to run the exe there by going to the appropriate path and typing in the filename (e.g. C:\github\program\dist\main.py). Any errors thrown by the application will be printed in the command prompt window, without it automatically closing.

Solution 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.

Share:
13,259
Dylan Cross
Author by

Dylan Cross

I'm not formally a programmer, but work as a Supply Chain Analyst where I regularly use Python, R, SQL, excel, and other software. I do enjoy writing code, and find StackOverflow a very helpful resource.

Updated on June 27, 2022

Comments

  • Dylan Cross
    Dylan Cross almost 2 years

    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.

  • sjjk001
    sjjk001 almost 3 years
    This worked for me, I believe that it was because the folder with the same name as my script has the init.py file which makes it a module and pyinstaller was trying to build that, anyway you are a life saver thanks for that