You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ LC_ALL=zh_TW.euctw ./python
Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = (not set)
program name = './python'
isolated = 0
environment = 1
user site = 1
import site = 1
is in build tree = 1
stdlib dir = '/home/serhiy/py/cpython/Lib'
sys._base_executable = '/home/serhiy/py/cpython/python'
sys.base_prefix = '/usr/local'
sys.base_exec_prefix = '/usr/local'
sys.platlibdir = 'lib'
sys.executable = '/home/serhiy/py/cpython/python'
sys.prefix = '/usr/local'
sys.exec_prefix = '/usr/local'
sys.path = [
'/usr/local/lib/python311.zip',
'/home/serhiy/py/cpython/Lib',
'/home/serhiy/py/cpython/build/lib.linux-x86_64-3.11-pydebug',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
LookupError: unknown encoding: EUC-TW
Current thread 0x00007f1f24b4b280 (most recent call first):
<no Python frame>
It is one of standard glibc locales. Other unsupported locales are hy_AM.armscii8 and ka_GE.georgianps, but I suppose they are less used, and there is no much official documentation available for that encodings.
[edit @StanFromIreland/@encukou] Another unsupported locale is IBM-943 (Japanese shift_jis) (#130228)
PEP 686 makes UTF-8 Mode default since Python 3.15.
Until then, user can enable UTF-8 Mode by export PYTHONUTF8=1 in .bashrc.
I know, that is why I cc'ed you. This issue will be closed when that is implemented, but we are on 3.14 and not 3.15, do we still want a workaround here or do we want to just wait or implement it already?
I believe that the correct fix of this issue is to support iconv as a codecs provider by default. Locales on Posix systems can only have encodings supported by iconv. Similar issue was already solved on Windows -- all cpXXX codecs are now supported. I plan to do this, but it's difficult due to the difference in handling stateful encoding in iconv and Python.
$ LC_ALL=zh_TW.euctw python3.14
Python path configuration:
(...)
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
LookupError: unknown encoding: EUC-TW
Current thread 0x00007fef38d0ef00 [python3.14] (most recent call first):
<no Python frame>
On Python 3.15, it just works:
$ LC_ALL=zh_TW.euctw ./python
Python 3.15.0a0 (heads/split_unicode_format:1352259b1e9, Oct 2 2025, 12:46:51) [GCC 15.2.1 20250808 (Red Hat 15.2.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale; locale.getencoding()
'EUC-TW'
>>> import sys; sys.getfilesystemencoding()
'utf-8'
Well, "just works" can be interpreted in different ways 😄
It's well possible that you get mojibake filenames when writing files to the FS with Python 3.15, or you fail to open a file, because the UTF-8 does not match the actual FS encoding.
Still, after all these years with Unicode, I think we can expect file systems to use UTF-8, just as much as we can expect terminals to run in UTF-8 mode, so I wouldn't worry too much.
It may be helpful to issue a warning, if there's a mismatch between the detected FS encoding and UTF-8, just to highlight the problem.
It's well possible that you get mojibake filenames when writing files to the FS with Python 3.15, or you fail to open a file, because the UTF-8 does not match the actual FS encoding.
Well, that's the PEP 686 – Make UTF-8 mode default. The PEP was accepted while we were well aware of the mojibake issue. Let's see how Python 3.15 goes :-)
Yes, I know and as I have mentioned elsewhere, I have been using UTF-8 mode for many years without any problems. It actually helped a lot in some situations, since the FS encoding is not something you can easily determine. It depends on the FS mount you are using and its configuration.
UTF-8 mode is default now, so this will only affect users that explicitly turn UTF-8 mode off and use an encoding that Python has never supported.
I agree that correct fix of this issue is to support iconv, but honestly, it doesn't seem to be worth the effort. @serhiy-storchaka, do you still plan to do this?
Also, this is not a crash; it's a clean failure. It just doesn't have a regular traceback since it occurs too early.
Activity
methane commentedon May 2, 2022
Maybe, enable UTF-8 Mode when locale encoding is not found?
vstinner commentedon May 25, 2022
https://peps.python.org/pep-0686/ may fix the issue :-) cc @methane
StanFromIreland commentedon Feb 17, 2025
Another instance of this #130228 with the IBM-943 (Japanese shift_jis) locale
StanFromIreland commentedon Apr 4, 2025
I can get it to work forcing it to utf-8 in:
cpython/Python/initconfig.c
Lines 2276 to 2280 in 7473c60
I could implement a fallback, but the question is, is there even a point? PEP 686 will force it to UTF8 if I am reading it correctly.
So, do we want fallback, or could we just implement the PEP now?
cc @methane
And do we also want a SC decision?
methane commentedon Apr 5, 2025
@StanFromIreland PEP 686 makes UTF-8 Mode default since Python 3.15.
Until then, user can enable UTF-8 Mode by
export PYTHONUTF8=1in .bashrc.StanFromIreland commentedon Apr 5, 2025
Duplicate: #63658
StanFromIreland commentedon Apr 5, 2025
I know, that is why I cc'ed you. This issue will be closed when that is implemented, but we are on 3.14 and not 3.15, do we still want a workaround here or do we want to just wait or implement it already?
methane commentedon Apr 5, 2025
It depends on how 'zh_TW.euctw' is used. If there are some users in the wild, we should add it to alias.
For example, #131370 (comment)
StanFromIreland commentedon Sep 29, 2025
I propose a more general solution to this problem in #139429 as I discussed with @malemburg some time ago.
2 remaining items
StanFromIreland commentedon Sep 29, 2025
It is still a crash on 3.13 and 3.14?
serhiy-storchaka commentedon Sep 30, 2025
I believe that the correct fix of this issue is to support iconv as a codecs provider by default. Locales on Posix systems can only have encodings supported by iconv. Similar issue was already solved on Windows -- all cpXXX codecs are now supported. I plan to do this, but it's difficult due to the difference in handling stateful encoding in iconv and Python.
vstinner commentedon Oct 2, 2025
Python fails to start on 3.14:
On Python 3.15, it just works:
malemburg commentedon Oct 2, 2025
Well, "just works" can be interpreted in different ways 😄
It's well possible that you get mojibake filenames when writing files to the FS with Python 3.15, or you fail to open a file, because the UTF-8 does not match the actual FS encoding.
Still, after all these years with Unicode, I think we can expect file systems to use UTF-8, just as much as we can expect terminals to run in UTF-8 mode, so I wouldn't worry too much.
It may be helpful to issue a warning, if there's a mismatch between the detected FS encoding and UTF-8, just to highlight the problem.
vstinner commentedon Oct 3, 2025
Well, that's the PEP 686 – Make UTF-8 mode default. The PEP was accepted while we were well aware of the mojibake issue. Let's see how Python 3.15 goes :-)
malemburg commentedon Oct 3, 2025
Yes, I know and as I have mentioned elsewhere, I have been using UTF-8 mode for many years without any problems. It actually helped a lot in some situations, since the FS encoding is not something you can easily determine. It depends on the FS mount you are using and its configuration.
encukou commentedon Oct 6, 2025
UTF-8 mode is default now, so this will only affect users that explicitly turn UTF-8 mode off and use an encoding that Python has never supported.
I agree that correct fix of this issue is to support iconv, but honestly, it doesn't seem to be worth the effort. @serhiy-storchaka, do you still plan to do this?
Also, this is not a crash; it's a clean failure. It just doesn't have a regular traceback since it occurs too early.
serhiy-storchaka commentedon Oct 6, 2025
Yes, I planned to do this in any case. Support of iconv is needed to support of all locales.
This is a crash, even if it was caused by the call of
Py_FatalError()instead of segmentation fault.BTW, I cannot run the debugger in non-UTF-8 locale:
vstinner commentedon Oct 6, 2025
You might try to set the environment inside gdb, not outside, using
(gdb) set environcommand.serhiy-storchaka commentedon Oct 6, 2025
But you cannot run it in an existing environment at first place if it is not UTF-8.
serhiy-storchaka commentedon Jul 9, 2026
Python no longer fails to start in the
zh_TW.euctwlocale since 3.15, even though it ships no EUC-TW codec.On top of that, the iconv-based codec engine added in #152997 (PR #153001) provides actual
EUC-TWsupport in 3.16 on platforms whoseiconv()has it.Closing as resolved.