Drekin / win-unicode-console

A Python package to enable Unicode support when running Python from Windows console.
MIT License
103 stars 12 forks source link

Can't run IDLE after enabling win-unicode-console #33

Open 5j9 opened 7 years ago

5j9 commented 7 years ago

As soon as I put

import win_unicode_console

win_unicode_console.enable()

in sitecustomize.py, IDLE won't run anymore (without showing any error message).

If I comment out the #win_unicode_console.enable() function call (only keeping the import statement) IDLE works again.

If I open an IDLE shell, reenable the win_unicode_console.enable(), then try to restart the shell, the following error shows up:


Subprocess Startup Error

IDLE's subprocess didn't make connection. Either IDLE can't start a subprocess or personal firewall software is blocking the connection.

OK

Another interesting observation is that calling py "C:\Users\a\AppData\Local\Programs\Python\Python35\Lib\idlelib\idle.pyw" in cmd works fine and IDLE gets launched. But if I call idle.pyw using pyw.exe (the way the IDLE shortcut works by default) then nothing happens:

C:\Users\a>pyw "C:\Users\a\AppData\Local\Programs\Python\Python35\Lib\idlelib\idle.pyw"

C:\Users\a>C:\Users\a\AppData\Local\Programs\Python\Python35\Lib\idlelib\idle.pyw

C:\Users\a>

I'm running

Does anyone know why this is happening?

Drekin commented 7 years ago

There is probably an exception in sitecustomize, but I don't know how to read the traceback when the application is GUI (i.e. run by pyw).

Drekin commented 7 years ago

This is a bug. Quick fix is to wrap win_unicode_console.enable() with try:…; except Exception: pass. I'll make a proper fix eventually.

5j9 commented 7 years ago

Thanks.

I guess you already have figured it out, but I had logged the exception before seeing you last comment:

To log the except I used logging in sitecustomize:

import win_unicode_console
import logging

logging.basicConfig(filename='pw_error.log',level=logging.DEBUG)

try:
    win_unicode_console.enable()
except Exception as e:
    logging.exception('Exception:')

And here is the error log:

ERROR:root:Exception:
Traceback (most recent call last):
  File "C:\Users\a\AppData\Local\Programs\Python\Python35\lib\site-packages\sitecustomize.py", line 7, in <module>
    win_unicode_console.enable()
  File "C:\Users\a\AppData\Local\Programs\Python\Python35\lib\site-packages\win_unicode_console\__init__.py", line 28, in enable
    streams.enable(stdin=stdin, stdout=stdout, stderr=stderr)
  File "C:\Users\a\AppData\Local\Programs\Python\Python35\lib\site-packages\win_unicode_console\streams.py", line 329, in enable
    sys.stdout.flush()
AttributeError: 'NoneType' object has no attribute 'flush'
ERROR:root:Exception:
Traceback (most recent call last):
  File "C:\Users\a\AppData\Local\Programs\Python\Python35\lib\site-packages\sitecustomize.py", line 7, in <module>
    win_unicode_console.enable()
  File "C:\Users\a\AppData\Local\Programs\Python\Python35\lib\site-packages\win_unicode_console\__init__.py", line 28, in enable
    streams.enable(stdin=stdin, stdout=stdout, stderr=stderr)
  File "C:\Users\a\AppData\Local\Programs\Python\Python35\lib\site-packages\win_unicode_console\streams.py", line 329, in enable
    sys.stdout.flush()
AttributeError: 'NoneType' object has no attribute 'flush'
Drekin commented 7 years ago

Yes, this is one bug. Another one is that the detection mechanisms shouldn't enable the streams at all.

eric-wieser commented 7 years ago

Can you change the readme to include this try except? Lost some time diagnosing this

Drekin commented 7 years ago

@eric-wieser Even better would be to actually fix the bug, by detecting IDLE properly. :-)

eric-wieser commented 7 years ago

@Drekin: Seems that it might just be that pythonw fails generally - launching idle from the command line with python -m idlelib.idle works fine, but pythonw -m idlelib.idle fails