Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--noconsole not working #654

Open
francescofact opened this issue Dec 18, 2022 · 9 comments
Open

--noconsole not working #654

francescofact opened this issue Dec 18, 2022 · 9 comments
Assignees

Comments

@francescofact
Copy link

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
Copy link

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

@snopedom
Copy link

@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
Copy link
Author

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
Copy link

JeswinSunsi commented Jan 12, 2023

@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
Copy link

woodrow-lwd commented Jan 29, 2023

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

@samuelhwilliams samuelhwilliams self-assigned this Feb 9, 2023
@samuelhwilliams samuelhwilliams pinned this issue Feb 9, 2023
@doug-benn
Copy link
Contributor

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

  • Doug

@davis-andy
Copy link

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
Copy link

IshuSinghSE commented Jul 17, 2024

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

ArabicGamerHackerMemeGIF

@bwoodsend
Copy link

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.

@samuelhwilliams samuelhwilliams unpinned this issue Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants