exe file made by pyinstaller has problem executing - python

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)

Related

Pyinstaller - failed to execute script: why?

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

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.

Python: no module named 'bottle-websocket' when running an executable made with PyInstaller, including Eel module

I was playing around with the eel module for Python - gives an opportunity to run HTML + CSS/JS with the python functionality.
Made a simple program, tried to make an executable out of it via PyInstaller.
No errors whatsoever, but when running this executable it crashes on the first line - import eel, telling - there is no module called 'bottle-websocket'.
I checked pip: eel, bottle-websocket are installed. Can't figure out what's the problem. Attachments:
main.py:
import eel
from os import path
eel.init(path.dirname(__file__) + "/web")
eel.start('main.html', block=False)
while True:
eel.sleep(10)
Error:
Picture with the error while I try to start the exe
EDIT:
PyInstaller Log
I was also having this same issue, but I finally fixed it, it was actually very very easy, first of all make sure you are using auto-py-to-exe to package your app.
After inserting necessary details (script file,, extra files etc), you would see an advanced options tab probably below, click on it to expand it, look for the hidden imports label and insert "bottle-websocket" in the input field representing the hidden imports, that's basically all you need to do
I HOPE THIS HELPS
Took me the whole day figuring out the solution, but finally, here it is:
Copy the plugin.py, server.py files from C:\Users\YOUR_USERNAME\AppData\Local\Programs\Python\Python36-32\lib\site-packages\bottle_websocket to C:\Users*YOUR_USERNAME*\AppData\Local\Programs\Python\Python36-32\Lib
Make sure you have this line as follows in your *.spec file generated by PyInstaller (FOR PYTHON 3.6 32bit):
datas=[('C:\Users\YOUR_USERNAME\AppData\Local\Programs\Python\Python36-32\lib\site-packages\eel\eel.js', 'eel'), ('PATH_TO_YOUR_WEB_FOLDER', 'YOUR_WEB_FOLDER_NAME')]
3)Run this command in cmd: python C:\Users\YOUR_USERNAME\AppData\Local\Programs\Python\Python36-32\lib\site-packages\eel\main.py HERE_SHOULD_BE_THE_PATH_TO_YOUR_WEB_FOLDER
this command will get the 'bottle-websocket' work and will make sure that it complies with the web folder and files.

how to execute python script on atom on windows

I am using Atom on Windows 10. While setting up Atom on my computer, I created a folder called "beyond basics". Then I created a python file. I installed platform io on Atom. i got a "+" icon on screen. upon clicking that i got a command line. I am trying to execute on that by writing python filename but I am getting an error. Any help is appreciated.
python3 myfile.py
Try typing myfile.py without the python prefix. It may work, as it works for me on Windows 10. Your bubble is covering up an error message that could help use debug. Can you add an edit and tell us the error message? Until then, just try the command without the python prefix.
You should also save before running, as was commented by Denis Fetinin.
If it still doesn't work, try addding python to the env variables. It's a simple process that you can follow here.

Categories

Resources