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.
Related
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
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)
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.
I have written a file pwrapper.py which imports another package that I have written packageapi. packageapi uses inspect module in the following instruction
print (inspect.getouterframes(inspect.currentframe())[1])
I have frozen pwrapper.py using pyinstaller.
When I launch pwrapper.exe from command line, everything works fine. I get the output
<frame object at 0x01234567> pwrapper.py 19 new_table [' packageapi.function()'] 0
However, when I launch pwrapper.exe by double clicking it, I get the following output
<frame object at 0x01234567> pwrapper.py 19 new_table None None
Why doesn’t the frame contain the lines and index when control is passed from pwrapper to packageapi.function when I double click on the exe?? I find it very weird that it behaves well when I run the exe from command line. Obviously there is something I don’t understand. Can someone help me fix it.
Thank you so much!
I got it to work. It turns out that I have to copy all the source code in the same directory structure but into the builds folder and it works fine now. I was hoping pyinstaller would do it, if that was mandatory!
Running pyinstaller with a prebuilt .spec file with a few added lines can copy over your source code automatically when building the exe.
No .spec file?
Running your .py file through pyinstaller will create a .spec file automatically.
If don't want to process everything and just to make the .spec file, run this-
pyi-makespec pwrapper.py
Then modify your .spec file similar to this (Windows example)-
addedFiles = {
('README.md','.'),
('folder\\specific.file','folder\\.'),
('folder2\\subFolder\\*.ext','folder2\\subFolder\\.'),
('fullFolder\\*','fullFolder\\.'),
}
a = Analysis([...]
datas=addedFiles ,
[...])
Then to run pyinstaller, point it to your .spec file instead of your .py file
pyinstaller pwrapper.spec
You can see an example where I'm using this method here-
pxlViewer.spec
I have created a working GUI program (using tkinter), but when I try to compile it using pyinstaller (py2exe only works for python 2.6 and I used 2.7 for the program), it doesn't work. I have 2 files: program.py, and data.xml. The program uses the xml document to retrieve information and display it to the window. I have looked all over, but no one seems to have had a similar problem, and the pyinstaller documentation is useless. the command I used was
python pyinstaller.py -w -mdata.xml -nProgram program.py
It appears to make the spec file fine, but generates an error with a large traceback upon build:
pyinstaller.utils.winmanifest.invalidManifestError: Invalid root element <items> - has to be one of <assembly>, <assemblyBinding>, <configuration>, <dependentAssembly>
and quits the build process. This is the first time I have tried to build an executable for a project, so I'm kind of shooting in the dark here. Did I forget to do something, or did I just find a bug in pyinstaller's program?
Normally I wouldn't answer my own question, but I have solved the issue and I think others should know about this. When creating your program and using an xml with it, you must have the root tag (the first one) as <assembly>. Not sure why, but it works when I do that. also, don't forget to use the --hidden-import=Module command if you imported anything into your program.