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

Unable to run with pythonw or PyInstaller #1044

Closed
simonrob opened this issue Feb 13, 2023 · 1 comment · Fixed by #1048 or #1086
Closed

Unable to run with pythonw or PyInstaller #1044

simonrob opened this issue Feb 13, 2023 · 1 comment · Fixed by #1048 or #1086

Comments

@simonrob
Copy link
Contributor

simonrob commented Feb 13, 2023

#1029 reported an issue with PyInstaller that was resolved for the original reporter with the logwriter-bottle branch that was merged in #1038.

For me this does not fix the issue, because bottle, which is causing the problem, requires stdout and stderr to exist before it is even imported. On Windows, neither pythonw nor PyInstaller support this.

To replicate without needing PyInstaller, run the pywebview Hello World example with pythonw rather than python. This is a regression since pywebview version 4.0 because of the introduction of bottle.

One fix would be to import bottle after the new DummyLogWriter, and change the hasattr(sys, '_MEIPASS') check in http.py to instead check for stdout and stderr existing (similar to how this used to work in PyInstaller).

The root cause is that bottle, for almost its entire existence until relatively recently, tested for the write method of stdout and stderr, but only caught an IOError, not an AttributeError. This was fixed in 2021, but it doesn't seem like a new PyPi release is coming anytime soon, so most pywebview users will probably have the latest version (0.12.23) that does not include this change.

I'm happy to submit a PR, but thought you might have your own preferred way of resolving things like this that are related to importing dependencies.

@codedocta

This comment was marked as off-topic.

simonrob added a commit to simonrob/pywebview that referenced this issue Feb 16, 2023
Bottle.py versions prior to 0.12.23 (the latest on PyPi as of Feb 2023) require stdout and stderr to exist when that package is imported, which is not the case on Windows when using pythonw.exe or PyInstaller >= 5.8.0.
This is similar to the recently-merged PR r0x0r#1038 that fixed r0x0r#1029, but this fix only works if using bottle.py 0.13-dev, which is unlikely in most cases given that this version is not on PyPi (note that the fix it contains was committed over two years ago in January 2021).
This change uses a `TemporaryFile` instead of `DummyLogWriter` to resolve the issue.
Fixes r0x0r#1044.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants