Pyinstaller - failed to execute script: why? - python

Fatal Error Detected: Failed to execute script main
I used the following tags:
pyinstaller --onefile -w main.py
I had dependencies, so when it finished, I moved the exe file to the main directory. I'm still getting an error. I used pygame for my project. Why?

I found the answer to my problem. It turns out, it had nothing to do with images. It had to do with the font. Normally, in PyCharm (maybe I'm mistaken) freesansbold.ttf is a default font. However, when PyInstaller packages the files, PyInstaller doesn't have the font downloaded by default, so it gives an error. All I had to do was scour the internet for the font, downloaded it, and it worked.
So yeah, pretty funny mistake.

When you are converting a .py file into .exe, PyInstaller shows the console. If there is an error in your code, it will be displayed in the command prompt.
But if you are converting a .pyw file into .exe, the error will be returned in the form of a message box instead.
So, to see your error (it is really quick though, but it is better than nothing), simply convert your file in .py format into an .exe, to see the error in the command prompt.
But when no window has been open, if there is an error at the beginning of the script, PyInstaller will not detect it as launched, so it will not show an error.
for example this program works, even if there is an error in the code:
avkzebhrkjvzebverybvzkejhrv

Related

pyinstaller .exe runs from command line, not double click in explorer

This has been asked several times before, but the answers don't seem to apply.
I create the exe with this command -
pyinstaller --onefile --add-binary C:\ProgramData\Anaconda3\Library\bin\mkl_intel_thread.1.dll;. unitTracker.py
If I run from the command line it works with no error msgs. If I double click in the File Explorer, the cmd window pops ups, sits around a while, then disappears, never visibly showing an error msg.
I created a simple .bat file:
unitTracker.exe
pause
Now the cmd window stays open after the .exe has run, but it shows nothing.
I added some diagnostic print() to my program, which now starts with:
if (__name__ == '__main__'):
print ('starting')
app = QtWidgets.QApplication(sys.argv)
print ('app created')
myapp = UnitTracker()
myapp.show()
sys.exit(app.exec())
I don't even get the "Starting" output, which suggests the problem is occurring before my program is even loaded.
The problem remains if I remove --onefile
Edit:
I realized that the cmd window in which the program successfully runs is an Anaconda window, whereas double clicking the .bat file produces a default cmd shell. That's one difference. I further refined this to checking the Anaconda env. The program runs in the env that pyinstaller was run in. It does not run in the base Anaconda environment. Isn't pyinstaller supposed to create a standalone program/bundle that doesn't rely on the environment? I know that sometimes it doesn't bundle a .dll without additional prompting, but in that case you get an error that the .dll was not found. I'm getting nothing.
Edit 2:
After a lot of hunting around, I was able to narrow it to a single import, which then allowed me to find the missing module in the huge list of missing modules.
missing module named 'lxml.etree' - imported by openpyxl.xml (delayed, optional), openpyxl.xml.functions (conditional), sphinxcontrib.devhelp (optional)
I've attempted to fix this by adding a --paths= flag pointing to the location of the relevant modules but I can't seem to get the right path. Going to keep banging on it.
Edit 3:
Here's an MWE for the issue:
from openpyxl import Workbook
if (__name__ == '__main__'):
print ("Hello World")
The code will run in the Ananconda shell in which pyinstaller was run. Run from cmd shell and you get nothing.
The warn-test.txt file indicates a missing module lxml.tree, as above.
This issue on the pyinstaller github repo shows the same problem. The solution posted there uses
--collect-submodules lxml
I tried that, but I'm still getting a missing module.
Edit 4:
Although the program runs in the Anaconda env it was built in, it turns out the env does not include lxml. I installed it and the problem has finally gone away.

exe file made by pyinstaller has problem executing

Here is python script:
I used Visual Studio Code to run the file with this command:
And I get desired result:
Now I tried to create .exe file by opening PowerShell in the folder where is my script and
running next line:
Here is stuff I got(not including otherScripts folder):
Now I open CMD, navigate to the desired folder, and run the .exe file with the next lines of code:
Here is what I get as my first warning:
And here is what I get as a Traceback(console instantly closed and I could not use the snipping tool to capture what was an error, so I run it through C# Win Form application and redirected standard error to a label in form):
I tried:
pip install transformers -U.
instead of --onefile, use command --onedir
line 3 (import tqdm) in the script, was recently added to try to fix the error. Because it says that "tqdm was not found and is required by the application.", so I just put it there.
Updating pyinstaller and transformers to the latest versions.
Other stuff I don't remember right now.
None of these things worked. And I'm kinda stuck here.
I would really appreciate any help to fix this problem.
for me adding the "tqdm directories" to datas solved the problem :)
In script.spec:
datas=[
('C:\\<...>\\Lib\\site-packages\\tqdm', 'tqdm\\'),
('C:\\<...>\\Lib\\site-packages\\tqdm-4.50.2.dist-info', 'tqdm-4.50.2.dist-info\\'),
...],
Try building with --exclude-module=torch?(Taken from: https://github.com/pyinstaller/pyinstaller/issues/4695)

Error when transforming my Python code to .EXE using Auto Py to Exe

After converting my Python code to an executable, I am getting the following fatal errors when trying to run the program:
1. Failed to run pyiboot01_bootstrap script
2. Error: "NoneType" object has no attribute "write"
3. Error described in the figure: pic3.jpg
Error 3
Note: The program works perfectly when running on VS Code. The program is basically an interface that extracts data from a text file. I attached the program below and the screens with the code that generated my .exe file
Any suggestions?
The problem may be with pyinstaller itself..
Reinstall pyinstaller and auto-py-to-exe and try again..

Python app not working after using pyinstaller but doesn't give any errors

So I made an app using python and kvlang, and I was trying to get all the files into a one standalone "exe" file. I needed to include the ".kv" file and my main script. I was using pyinstaller and wrote this command:
pyinstaller --onefile -w --icon=download.ico --add-data filefinder.kv;. filefinder.py
And it all went well - no errors or anything but when I launch the app I just get a quick flash of a white window and then it closes. I have determined that the error must be because of some issue with the ".kv" file but I am not able to fix it cause there's no errors, Nothing! I checked and the app works with the "onedir" option but I need to make it smaller in size. I also tried the "auto-py-to-exe" but it gives the same result. I am happy to provide any more info should you need it to help me resolve this issue. Cheers!
Additional info:
System: Windows 10 pro
Python: 3.9.1
kivy: 2.0.0
Pyinstaller: 4.2
Not sure why it doesn't work, but run the exe in command prompt and then when it fails the error message will not disappear.
Add lots of logs to your application, these can be print statements, as those will always end up on stdout.
i.e. on the first entrypoint, print("Running main")
When you call your first function:
print('calling function_name()')
Once that has finished
print('function_name() complete')
And so on and so forth until you find where exactly the program stops functioning.
Start -> cmd -> navigate to your file using cd -> type in the name of the exe to run it.

pyinstaller questions and issues

I am using python 3.6.8 with Linux ubuntu and I have a py.file (pyinst_tester.py) that I want to test pyinstaller with:
I have three files (pyinst_tester.py) (bell.mp3) (filetotestadd.txt)
The (pyinst_tester.py), plays a bell sound, only after reading a play command from the text file (filetotestadd.txt)
If I use pyinstaller, i can get this to work, however, when (pyins_teseter.py) turns to an EXE....it does not contain (bell.mp3) or (filetotestadd.txt), as removal of either of them from the directory, gives no sound.
as instructed in the pyinstaller manual and it is added to the spec file indeed as expected, but I would have thought that when you make a single file EXE, it contains, (filetotestadd.txt) and (bell.mp3) INSIDE IT thus making these files redundant from the directory they are in and irrelevant to the EXE...thus removable.
AM I missing something ??...and if not, how can i get one EXE file, that has both, the mp3 and the text file INSIDE IT ?
Thank you
What am I not understanding properly.
I tried:
pyinstaller -F --add-data 'filetotestadd.txt:.' pyinst_tester.py
this is the code I am trying to turn to exe.
import subprocess
f=open('testfile1','w')
f.write('This has worked')
f.close()
f=open('testfile1','r')
test=f.readline()
f.close()
print(test)
f=open('filetotestadd.txt','r')
read=f.readline()
if 'play' in read:
subprocess.call(['cvlc','bell.mp3'])
I am closing this question. I have tried everything and i cannot do it. and i am getting no more feedback. therefore i am going to close it.
pyinstaller -F --add-data doesnt do it.

Categories

Resources