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

Compiling with --noconsole option causes crash #134

Closed
bwbug opened this issue Feb 8, 2023 · 7 comments
Closed

Compiling with --noconsole option causes crash #134

bwbug opened this issue Feb 8, 2023 · 7 comments

Comments

@bwbug
Copy link

bwbug commented Feb 8, 2023

I used the installation instructions for creating a self-contained executable using pyinstaller, and confirmed that this works. However, the executable runs in a console, and closing the console window unfortunately also eliminates the systray icon. Unfortunately, closing the console is easy to do by accident, and in addition, the console creates a taskbar button that takes up valuable space in the taskbar.

I've attempted to compile an executable that does not have a console, using the --noconsole option, as follows:

pyinstaller --noconsole --onefile emailproxy.py --hidden-import timeago.locales.en

However, running the resulting executable produces the following run-time error:

image

The full text of the error message is shown below.

Traceback (most recent call last):
  File "emailproxy.py", line 74, in <module>
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "webview\__init__.py", line 22, in <module>
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "webview\http.py", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "bottle.py", line 73, in <module>
AttributeError: 'NoneType' object has no attribute 'write'

 
Is there any way to run the proxy (in Windows 10) without the console?

@bwbug
Copy link
Author

bwbug commented Feb 8, 2023

I also tried pythonw emailproxy.py but this failed silently (no systray icon).

@simonrob
Copy link
Owner

simonrob commented Feb 8, 2023

Thanks for reporting this. I can replicate the issue, but it is related to this change in PyInstaller 5.7.0, and is caused by pywebview not the proxy. There is an explanation of the reason in this issue on a different project. In summary, PyInstaller has changed the way that stdout and stderr are handled in --noconsole mode on Windows. I added a bit of context to an existing pywebview issue; hopefully this can be resolved.

In the meantime, downgrade your version of PyInstaller to fix this: python -m pip install pyinstaller==5.6.2 (or use --no-gui mode in the proxy).


I also tried pythonw emailproxy.py but this failed silently (no systray icon).

Where are you running that pythonw command from? For me, Command Prompt works fine, but in PowerShell I need to redirect/suppress the output streams (e.g., pythonw emailproxy.py *>$null).

Incidentally, if you use the proxy's Start at Login option it will generate a single file in shell:startup that you can click to launch the proxy if that is what you're primarily looking for here.

@bwbug
Copy link
Author

bwbug commented Feb 8, 2023

Thank you for your response.

In the meantime, downgrade your version of PyInstaller to fix this: python -m pip install pyinstaller==5.6.2 (or use --no-gui mode in the proxy).

I will try the first suggestion, but I thought --no-gui would suppress the systray icon also?

What I would like is to launch the proxy so that systray icon is available, but the console window is suppressed or hidden. I never got far enough with the startup file ("Start at login" option) to determine if that would produce the desired behavior. In any case, I may want to launch the proxy on-demand (without the console) instead of on startup.

When I did attempt to use the "Start at login" option, I had troubles with that, too, as reported in issue #135. I also tried start /b, but that didn't help.

@bwbug
Copy link
Author

bwbug commented Feb 8, 2023

Since downgrading pyinstaller may not be a future-proof solution, is it possible to do an alternative work-around similar to the one proposed for Kivy here?

@simonrob
Copy link
Owner

simonrob commented Feb 8, 2023

Yes, --no-gui suppresses the systray icon, hence why it also fixes this GUI-related issue. Downgrading PyInstaller will achieve what you want here – it may not be a viable option forever, but I suspect the core issue will be fixed via pywebview well before that becomes a problem.

@simonrob
Copy link
Owner

simonrob commented Feb 9, 2023

Pywebview's author has already proposed a fix for this – please could you test by installing the branch via python -m pip install https://github.com/r0x0r/pywebview/archive/logwriter-bottle.zip (and upgrading to PyInstaller >= 5.7.0) and let me know whether this resolves the issue?

@simonrob
Copy link
Owner

I recently reported a related issue to pywebview and proposed a fix that has now been merged (see the pywebview report for details).

I will leave this issue open until it is possible to pin a specific released version of pywebview in the proxy's requirements, but until then it can be resolved by force installing the fixed version: python -m pip install git+https://github.com/r0x0r/pywebview.git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants