python-eel / Eel

A little Python library for making simple Electron-like HTML/JS GUI apps
MIT License
6.41k stars 586 forks source link

--noconsole not working #654

Open francescofact opened 1 year ago

francescofact commented 1 year ago

Hello, I've built an app with eel and now I'm trying to make an executable from it. But if I try to disable the console it doesn't start and shows the following error:

error

I'm using this command: python -m eel app.py web --onefile --noconsole --splash splash.png

and from python I just runeel.start('index.html')

I tried to redirect sys.stderr and sys.stdout to a StringIO or a PIPE but still the error popup. I'm on windows and the app runs with Chrome.

lucasadsouza commented 1 year ago

Same here, trying to find a solution or workaround, but no lucky until now... let me know if you find something, please

snopedom commented 1 year ago

@francescofact @lucasadsouza We faced same problem on project. This soulution is not maybe for everyone but as a workaround will help you. Attempt to redirect sys.stderr and sys.stdout somewhere was right way but only redirect to /dev/null works for us.

Version: eel v0.15.0 with electron Cmd: python -m eel main.py web --noconsole --onefile

import os
import sys

f = open(os.devnull, 'w')
sys.stdout = f
sys.stderr = f

import eel
francescofact commented 1 year ago

Thank you. I also figure out a similar temporary solution. Put this snippet at the very top of the code, also Upper then libraries

import sys, io
sys.stdout = io.StringIO()
sys.stderr = io.StringIO()
JeswinSunsi commented 1 year ago

@francescofact @snopedom @lucasadsouza Here's another solution that I used for a project a couple years back. It's working as of November 2022.

import ctypes

def hideConsole():
    whnd = ctypes.windll.kernel32.GetConsoleWindow()
    if whnd != 0:
        ctypes.windll.user32.ShowWindow(whnd, 0)

hideConsole()
woodrow-lwd commented 1 year ago

Thank you. I also figure out a similar temporary solution. Put this snippet at the very top of the code, also Upper then libraries

import sys, io
sys.stdout = io.StringIO()
sys.stderr = io.StringIO()

it's work for me. just need to write this code snippet before import eel

doug-benn commented 1 year ago

Hello,

This is odd because I am using a chrome-app binary created with --noconsole --onefile.

Works fine for chrome but not edge which I fixed here: #626

Thanks

davis-andy commented 1 year ago

I ran into this issue as well and it might be a bottle issue since the screenshot shows from file bottle.py line 73, which shows this:

72: try:
73:    _stdout, _stderr = sys.stdout.write, sys.stderr.write
74: except IOError:
75:     _stdout = lambda x: sys.stdout.write(x)
76:     _stderr = lambda x: sys.stderr.write(x)

using --noconsole causes an AttributeError (probably because the console does not exist so there is nothing to write to)

I sort of did this in my bottle files before running pyinstaller, which may not be the best solution but was a temp fix that worked for me:

72: try:
73:    _stdout, _stderr = sys.stdout.write, sys.stderr.write
74: except IOError:
75:     _stdout = lambda x: sys.stdout.write(x)
76:     _stderr = lambda x: sys.stderr.write(x)
77: except AttributeError:
78:     pass

Not sure what can really be done for it

IshuSinghSE commented 2 months ago

Thanks for the workaround, You're surely a Hacker 🧑‍💻😁

ArabicGamerHackerMemeGIF

bwoodsend commented 2 months ago

The correct fix is just to check that sys.stdout/sys.stderr aren't None before attempting to use them.

if sys.stderr:
     sys.stderr.write("...")

This is in both Python and PyInstaller's documentation.