Message408474
Eric, I have a simple reproducer for the issue:
This works:
$ LC_ALL=en_US.utf-8 TESTPATH=$(pwd)/Lib:$(pwd)/build/lib.linux-x86_64-3.11 ./Programs/_testembed test_init_setpath_config
This fails because it cannot load ISO-8859-1 / latin-1 codec
$ LC_ALL=en_US.latin1 TESTPATH=$(pwd)/Lib:$(pwd)/build/lib.linux-x86_64-3.11 ./Programs/_testembed test_init_setpath_config
Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = (not set)
program name = 'conf_program_name'
isolated = 0
environment = 1
user site = 1
import site = 1
is in build tree = 0
stdlib dir = ''
sys._base_executable = 'conf_executable'
sys.base_prefix = ''
sys.base_exec_prefix = ''
sys.platlibdir = 'lib'
sys.executable = 'conf_executable'
sys.prefix = ''
sys.exec_prefix = ''
sys.path = [
'/home/heimes/dev/python/cpython/Lib',
'/home/heimes/dev/python/cpython/build/lib.linux-x86_64-3.11',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
LookupError: unknown encoding: ISO-8859-1
Current thread 0x00007f9c42be6740 (most recent call first):
<no Python frame>
With this patch I'm seeing that encodings.__path__ is not absolute and that __spec__ has an empty submodule_search_locations.
--- a/Lib/encodings/__init__.py
+++ b/Lib/encodings/__init__.py
@@ -98,9 +98,12 @@ def search_function(encoding):
# module with side-effects that is not in the 'encodings' package.
mod = __import__('encodings.' + modname, fromlist=_import_tail,
level=0)
- except ImportError:
+ except ImportError as e:
# ImportError may occur because 'encodings.(modname)' does not exist,
# or because it imports a name that does not exist (see mbcs and oem)
+ sys.stderr.write(f"exception: {e}\n")
+ sys.stderr.write(f"encodings.__path__: {__path__}\n")
+ sys.stderr.write(f"encodings.__spec__: {__spec__}\n")
pass
else:
break
$ LC_ALL=en_US.latin1 TESTPATH=$(pwd)/Lib:$(pwd)/build/lib.linux-x86_64-3.11 ./Programs/_testembed test_init_setpath_config
exception: No module named 'encodings.latin_1'
encodings.__path__: ['encodings']
encodings.__spec__: ModuleSpec(name='encodings', loader=<class '_frozen_importlib.FrozenImporter'>, origin='frozen', submodule_search_locations=[])
exception: No module named 'encodings.iso_8859_1'
encodings.__path__: ['encodings']
encodings.__spec__: ModuleSpec(name='encodings', loader=<class '_frozen_importlib.FrozenImporter'>, origin='frozen', submodule_search_locations=[])
It should have this search location:
>>> import encodings
>>> encodings.__spec__
ModuleSpec(name='encodings', loader=<class '_frozen_importlib.FrozenImporter'>, origin='frozen', submodule_search_locations=['/home/heimes/dev/python/cpython/Lib/encodings']) |
|
Date |
User |
Action |
Args |
2021-12-13 18:01:38 | christian.heimes | set | recipients:
+ christian.heimes, lemburg, gvanrossum, eric.snow, FFY00, kumaraditya |
2021-12-13 18:01:38 | christian.heimes | set | messageid: <1639418498.93.0.611873850949.issue45653@roundup.psfhosted.org> |
2021-12-13 18:01:38 | christian.heimes | link | issue45653 messages |
2021-12-13 18:01:38 | christian.heimes | create | |
|