[osgeo4w-dev] [osgeo4w] #422: Add sitecustomize.py to set Python default encoding to UTF-8

OSGeo4W trac_osgeo4w at osgeo.org
Sat Jun 7 03:01:21 PDT 2014


#422: Add sitecustomize.py to set Python default encoding to UTF-8
---------------------+------------------------------------------------------
Reporter:  akaginch  |       Owner:  osgeo4w-dev@…              
    Type:  defect    |      Status:  new                        
Priority:  major     |   Component:  Package                    
 Version:            |    Keywords:  python27,i18n              
---------------------+------------------------------------------------------
 Since the default encoding of Python 2.x is ASCII, encoding / decoding
 strings that include non-ASCII characters without explicitly specified
 encoding causes UnicodeEncodeError / UnicodeDecodeError.[[BR]]
 [[BR]]
 Some useful QGIS plugins (e.g. some algorithms of Processing, and mmqgis)
 can not be used with non-ASCII data because of this error.
 We can avoid these errors by simply changing the default encoding to
 UTF-8.
 There is no problem related to this change with users who use only ASCII
 characters.
 In Python 3.x, the default encoding is UTF-8.
 [[BR]]
 [[BR]]
 Python code authors still need to pay attention to encoding when writing a
 code which handles file path or non-UTF-8 data, but have no need to pay
 attention at any other time.


 python27\lib\site-packages\sitecustomize.py:
 {{{
 import sys
 sys.setdefaultencoding("utf-8")
 }}}

-- 
Ticket URL: <http://trac.osgeo.org/osgeo4w/ticket/422>
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