[osgeo4w-dev] [osgeo4w] #682: MSI and EXE installers: different Python locale settings leads to issues with the Python console script editor

OSGeo4W trac_osgeo4w at osgeo.org
Wed Jun 23 01:25:46 PDT 2021


#682: MSI and EXE installers: different Python locale settings leads to issues
with the Python console script editor
------------------------+----------------------------
Reporter:  andreaerdna  |       Owner:  osgeo4w-dev@…
    Type:  defect       |      Status:  new
Priority:  major        |   Component:  Package
 Version:               |  Resolution:
Keywords:               |
------------------------+----------------------------

Comment (by andreaerdna):

 It seems Python used in QGIS is not affected by the PYTHONUTF8 env var,
 while the Python used in OSGeo4W console is affected:

 **OSGeo4W old repositroy, OSGeo4W console**:

 {{{
 F:\QGIS\OSGeo4W_3.18.1\qgis>python-qgis
 Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit
 (AMD64)] on win32
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import os
 >>> os.environ['PYTHONUTF8']
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "F:\QGIS\OSGEO4~1.1\qgis\apps\Python37\lib\os.py", line 678, in
 __getitem__
     raise KeyError(key) from None
 KeyError: 'PYTHONUTF8'
 >>> import sys
 >>> sys.flags.utf8_mode
 0
 >>> import locale
 >>> locale.getpreferredencoding(False)
 'cp1252'
 }}}


 {{{
 F:\QGIS\OSGeo4W_3.18.1\qgis>set PYTHONUTF8=1

 F:\QGIS\OSGeo4W_3.18.1\qgis>python-qgis
 Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit
 (AMD64)] on win32
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import os
 >>> os.environ['PYTHONUTF8']
 '1'
 >>> import sys
 >>> sys.flags.utf8_mode
 1
 >>> import locale
 >>> locale.getpreferredencoding(False)
 'UTF-8'
 }}}



 {{{
 F:\QGIS\OSGeo4W_3.18.1\qgis>set PYTHONUTF8=0

 F:\QGIS\OSGeo4W_3.18.1\qgis>python-qgis
 Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit
 (AMD64)] on win32
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import os
 >>> os.environ['PYTHONUTF8']
 '0'
 >>> import sys
 >>> sys.flags.utf8_mode
 0
 >>> import locale
 >>> locale.getpreferredencoding(False)
 'cp1252'
 }}}


 **OSGeo4W old repositroy, QGIS Python console**:


 {{{
 sys.version
 '3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit
 (AMD64)]'
 os.environ["PYTHONUTF8"]
 Traceback (most recent call last):
   File "F:\QGIS\OSGEO4~1.1\qgis\apps\Python37\lib\code.py", line 90, in
 runcode
     exec(code, self.locals)
   File "<input>", line 1, in <module>
   File "F:\QGIS\OSGEO4~1.1\qgis\apps\Python37\lib\os.py", line 678, in
 __getitem__
     raise KeyError(key) from None
 KeyError: 'PYTHONUTF8'
 sys.flags.utf8_mode
 -1
 import locale
 locale.getpreferredencoding()
 'UTF-8'
 }}}


 {{{
 sys.version
 '3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit
 (AMD64)]'
 os.environ["PYTHONUTF8"]
 '1'
 sys.flags.utf8_mode
 -1
 import locale
 locale.getpreferredencoding()
 'UTF-8'
 }}}


 {{{
 sys.version
 '3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit
 (AMD64)]'
 os.environ["PYTHONUTF8"]
 '0'
 sys.flags.utf8_mode
 -1
 import locale
 locale.getpreferredencoding()
 'UTF-8'
 }}}

-- 
Ticket URL: <https://trac.osgeo.org/osgeo4w/ticket/682#comment:5>
OSGeo4W <http://trac.osgeo.org/osgeo4w>
OSGeo4W is the Windows installer and package environment for the OSGeo stack.


More information about the osgeo4w-dev mailing list