[PyQt] Fwd: Logging UTF-8 when pyqtdeployed [CLOSED]
Dave Gradwell
davegradwell at yahoo.co.uk
Thu Feb 9 00:24:00 GMT 2017
Just for the archives…
To workaround this, I changed my Python Logging configuration:
from : logging.basicConfig(filename=APP_LOG_PATH, level=logging.DEBU…..
to : logging.basicConfig(handlers=[logging.FileHandler(filename=APP_LOG_PATH, encoding='utf-8')], level=logging.DEBU…...
With the explicit encoding parameter, UTF-8 characters are now logged without complaint.
During investigation, I dumped os.environ in the different launching contexts and noticed:
- When launched from PyCharm, PYTHONIOENCODING and LC_CTYPE are set to “UTF-8” and “en_US.UTF-8” respectively.
- When invoked by launching .app/Contents/MacOS/<binary> from the Terminal.app, LANG is set to "en_GB.UTF-8”.
- When launched by pyqtdeploy, LANG is set to "en_GB.UTF-8” (perhaps unsurprisingly, as pyqtdeploy was itself launched from Terminal.app and presumably confers its environment onto the binary it makes and launches).
- When the app is just double-clicked, however, no environment variables are set relating to any of PYTHONIOENCODING, LC_CTYPE or LANG. I see that __CF_USER_TEXT_ENCODING is set but I don’t think Python is particularly wowed by this.
I checked pyqtdeploy_start.cpp.
locale_codec_name is "UTF-8” (which is good).
I also hacked-in Py_SetStandardStreamEncoding("UTF-8", "strict”); just before Py_Initialize(); but this had no discernible effect.
I wonder if the lack of 'LANGUAGE', 'LC_ALL', 'LC_CTYPE' or ‘LANG’ is causing Python to fall back on a more primitive encoding...
locale.getdefaultlocale() consistently returns None, None.
Possibly of interest:
- https://docs.python.org/2/library/locale.html#locale.getdefaultlocale
- http://stackoverflow.com/questions/25661295/why-does-qcoreapplication-call-setlocalelc-all-by-default-on-unix-linux
Anyway I’m just sending this into the ether so maybe it can sit in the archives and possibly help someone else one day…
— Dave.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170208/4aa7aa7b/attachment.html>
More information about the PyQt
mailing list