Message 104932 - Python tracker (original) (raw)
Python3 is unable to start (bootstrap failure) on a POSIX system if the locale encoding is different than utf8 and the Python path (standard library path where the encoding module is stored) contains a non-ASCII character. (Windows and Mac OS X are not affected by this issue because the file system encoding is hardcoded.)
- Py_FileSystemDefaultEncoding == NULL
- calculate_path(): sys.path is filled with directory names decoded with the locale encoding
- find_module() encodes each path using PyUnicode_AsEncodedString(..., Py_FileSystemDefaultEncoding, NULL): use "utf-8" encoding because Py_FileSystemDefaultEncoding is NULL
=> error because the path is not encoded and decoded with the same encoding
We cannot encodes a path with the locale encoding because we need find_module() to load the encoding codec, and loading the codec needs find_module()... (bootstrap error :-))
We should decodes the path using a fixed encoding (eg. ASCII or utf-8), use the same encoding to encodes paths in find_module(), and then reencode paths of all objects storing filenames:
- sys.path list items
- sys.modules dict keys
- sys.modules values: each module have file and/or path attributes
- all code objects (co_filename)
- (maybe some other?)
The error occurs in an early stage of Py_InitializeEx(), so the object list is limited and we control this list (eg. site is not loaded yet).
Related issues: