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
Related
I used auto-py-to-exe to generate a exe file for my python code that inly runs in console window. I have noticed if I try to update my code for example adding on a new print statement it won't update. How should I fix this? I looked in file that auto-py-to-exe generated to hold my exe there was just a exe file in it nothing else for me to edit my code. So how do I edit it (the original python file and automatically update the exe)?
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 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.
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.
The problem is that I can not run Scrapy function inside my tkinter gui, when it's compiled to .exe
Everything works great, when I just run not compiled .py file
my setup file:
print('don"t look at this string, SO said it should be here')
https://pastebin.com/0ERecUaA
guess you do not need other 2 work .py files, because they work perfectly when I run them from console
BTW: I get no errors while processing compiling
solved by adding
"idna", "email.mime.multipart", "email.mime.text","email.mime"
to packages