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
{{ message }}
Repository navigation
site: Potential UnicodeDecodeError when handling pth file #87380
Since it's a Python script, the default encoding should be UTF-8, as any Python script. I guess that most pth files don't use characters outside ASCII so it's fine.
I think that distutils made a few changes to switch UTF-8 last years, so it's possible.
I'm having problem with UnicodeDecodeError in this situation.
I know it can be avoided using utf-8 mode, but utf-8 mode is not working with 3.11 nor 3.12 in my environment:
Windows 11
python 3.11.8 / 3.12.2
I'd appreciate if pth file encoding be utf8, or someone knows a workaround to make utf-8 mode available in python 3.11 and later.
(with python 3.10 or earlier, utf-8 mode is working fine.)
I'm using new project and package manager rye that creates a pth file that contains full path of the project, which often contains non-ascii characters in some countries. So this could happen more often when rye would get more popular I guess.
Activity
methane commentedon Feb 13, 2021
cpython/Lib/site.py
Line 160 in 4230bd5
When default text encoding is not UTF-8 and pth file contains non-ASCII character, it will raise UnicodeDecodeError.
methane commentedon Mar 17, 2021
locale-specific encoding is not good especially for Windows.
But we used it for a long time. Changing the encoding for pth files is breaking change.
vstinner commentedon Mar 17, 2021
Since it's a Python script, the default encoding should be UTF-8, as any Python script. I guess that most pth files don't use characters outside ASCII so it's fine.
I think that distutils made a few changes to switch UTF-8 last years, so it's possible.
wkwkw commentedon Apr 11, 2024
I'm having problem with UnicodeDecodeError in this situation.
I know it can be avoided using utf-8 mode, but utf-8 mode is not working with 3.11 nor 3.12 in my environment:
I'd appreciate if pth file encoding be utf8, or someone knows a workaround to make utf-8 mode available in python 3.11 and later.
(with python 3.10 or earlier, utf-8 mode is working fine.)
I'm using new project and package manager rye that creates a pth file that contains full path of the project, which often contains non-ascii characters in some countries. So this could happen more often when rye would get more popular I guess.
vstinner commentedon Apr 11, 2024
I suggest you to open a new issue since this one is closed.