Eel
Eel copied to clipboard
"Failed to execute script" when executing a pyinstaller noconsole exe that uses electron
Eel version v0.11
Describe the bug When executing a pyinstaller exe that was compiled using the --noconsole option and which makes use of electron, the app crashes with the error "Failed to execute script"
To Reproduce Steps to reproduce the behaviour:
- Compile electron using electron-builder
- Compile the exe using pyinstaller:
python -m eel ./src/main.py ./src/web/ --add-data="./dist/electron/;./electron/" --noconsole
- Execute the exe
Expected behaviour App works as usual
Error Output By including the following code at the top of the python file:
import sys
sys.stderr = open("error.log", "a")
The following output was observed:
Traceback (most recent call last):
File "src\MesIntegration.py", line 196, in <module>
File "lib\site-packages\eel\__init__.py", line 134, in start
File "lib\site-packages\eel\__init__.py", line 156, in show
File "lib\site-packages\eel\browsers.py", line 63, in open
File "lib\site-packages\eel\electron.py", line 11, in run
File "subprocess.py", line 728, in __init__
File "subprocess.py", line 1057, in _get_handles
AttributeError: 'NullWriter' object has no attribute 'fileno'
Possible Fix
I was able to stop the app crash by changing line 11 of electron.py to:
sps.Popen(cmd, stdout=sps.PIPE, stderr=sps.PIPE, stdin=sps.PIPE)
It seems a statement needs to be added that can recognise when the app is being run without a console and set stdout and stderr to sps.PIPE.
If anyone can suggest a way we might to do this, i would be willing to submit a pull request.
In the meantime using mode="custom" in eel.start() solves the crash as id prefer not to change library files
I'm facing the same issue with an older version of Eel. Searching on the web, I found this: https://github.com/pyinstaller/pyinstaller/wiki/Recipe-subprocess But doing the suggested fix (for me it is in chrome.py) doesn't seem to help. If I come up with something, I will post it here.
EDIT: Sorry for the confusion. Looking at the history the bug with Chrome was already fixed in #41: https://github.com/samuelhwilliams/Eel/issues/41
Sorry for not reaching out on this sooner.
Can someone confirm if this is still an issue please?
Yes this happened to me too. Somehow the --noconsole flag causes this. I've found out a possible workaround for this that works fine though.
def hideConsole():
whnd = ctypes.windll.kernel32.GetConsoleWindow()
if whnd != 0:
ctypes.windll.user32.ShowWindow(whnd, 0)
Then call hideConsole() somewhere in your script. Dont forget to import ctypes.
Same here.
When building with the --windowed
flag, my program raise OSError: [WinError 6] The handle is invalid
.
The problem can be "addressed" by not using the --windowed
flag.
Has anybody found the source of this problem?
Hi,
I am also having this issue. I believe the original poster has the issue correct. Just need to route stdout and stdin when being used without a console.
I was able to use a similar workaround to @ahobsonsayers, @g-berthiaume this may interest you..
eel.start( index.html, mode='custom' cmdline_args=[electron_path, .\index.js] )
@MikeKarnsTC Interesting. Thanks!
For me it seems to be a problem with bottle.py which tries to access sys.stdout. I currently go along with this workaround:
import sys
from io import StringIO
if sys.stdout is None:
sys.stdout = StringIO()
if sys.stderr is None:
sys.stderr = StringIO()
import eel