Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 is my python GUI program. When I run pyinstaller using this command:

pyinstaller.exe --onedir --hidden-import FileDialog --windowed --noupx new-app.py 

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\new-app\new-app.exe 

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?

I am using python2.7 and the OS is Windows 7 Enterprise.

Any inputs will be appreciated and thanks a lot in advance.

like image 343
aBiologist Avatar asked Nov 21 '16 09:11

aBiologist


People also ask

How do I fix PyInstaller not working?

To Solve 'pyinstaller' is not recognized as an internal or external command operable program or batch file Error You just need to add python script in your path to solve this error.

Does PyInstaller work on Windows?

PyInstaller supports making executables for Windows, Linux, and macOS, but it cannot cross compile.

Do you need Python to run a PyInstaller exe?

They do not need to have Python installed at all. The output of PyInstaller is specific to the active operating system and the active version of Python. This means that to prepare a distribution for: a different OS.


2 Answers

Well I guess I have found the solution for my own question, here is how I did it:

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.

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.

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!

So The Simple answer is to place all the media files or folders which were used by code in the directory where exe file is there.

Second method is to add "--add-data <path to file/folder>"(this can be used multiple times to add different files) option in pyinstaller command this will automatically put the given file or folder into the exe folder.

like image 146
aBiologist Avatar answered Sep 27 '22 00:09

aBiologist


In my case i have a main.py that have dependencies with other files. After I build that app with py installer using this command:

pyinstaller --onefile --windowed main.py 

I got the main.exe inside dist folder. I double clicked on this file, and I raised the error mentioned above. To fix this, I just copy the main.exe from dist directory to previous directory, which is the root directory of my main.py and the dependency files, and I got no error after run the main.exe.

like image 42
monti Avatar answered Sep 27 '22 00:09

monti