PYPY3 auf Windows 11 zeigt keine nicht ascii-Zeichen korrekt an
Posted: 14 Apr 2025, 11:50
pypy3 zeigt nicht ascii unicode-Zeichen korrekt an. < /p>
Ein einfaches Beispiel: < /p>
sollte auf meinen Benutzernamen bewerten: 'ξένη γήινος' .
Es gibt nur sehr wenige Informationen dazu, die ich durch Google -Suche finden kann, aber ich habe Folgendes festgestellt:
https://github.com/pypy/pypy/issues/4948
Dies ist ein bekanntes Problem. Linked Page, die von CPython verwendete Codierung und Gebietsschema sind: < /p>
Es erscheint daher offensichtlich, dass das Problem durch die Nichtübereinstimmung zwischen der Code -Seite Windows und der Code -Seite PYPY3 verursacht wird. Windows verwendet 'CP1252' und CPython verwendet dieselbe Code -Seite, aber PYPY3 nicht. Daher besteht die Korrektur darin, PYPY3 entweder zu erstellen, die "CP1252" Code-Seite verwenden oder Windows Console "UTF-8" verwenden.
Es gibt kein Reload in Python 3, und daher kann ich nicht sys.setDefaultCoding und Lokale verwenden.
Ein einfaches Beispiel: < /p>
Code: Select all
b'\xce\x9e\xce\xad\xce\xbd\xce\xb7 \xce\x93\xce\xae\xce\xb9\xce\xbd\xce\xbf\xcf\x82'.decode('utf8')
Code: Select all
In [1]: b'\xce\x9e\xce\xad\xce\xbd\xce\xb7 \xce\x93\xce\xae\xce\xb9\xce\xbd\xce\xbf\xcf\x82'.decode('utf8')
Out[1]: '╬×╬¡╬¢╬À ╬ô╬«╬╣╬¢╬┐¤é'
https://github.com/pypy/pypy/issues/4948
Dies ist ein bekanntes Problem. Linked Page, die von CPython verwendete Codierung und Gebietsschema sind: < /p>
Code: Select all
In [1]: import locale, os, sys
In [2]: locale.getdefaultlocale()
:1: DeprecationWarning: 'locale.getdefaultlocale' is deprecated and slated for removal in Python 3.15. Use setlocale(), getencoding() and getlocale() instead.
locale.getdefaultlocale()
Out[2]: ('en_US', 'cp1252')
In [3]: locale.getlocale()
Out[3]: ('English_United States', '1252')
In [4]: locale.getencoding()
Out[4]: 'cp1252'
In [5]: locale.LC_ALL
Out[5]: 0
In [6]: sys.getdefaultencoding()
Out[6]: 'utf-8'
< /code>
Und das ist das, was von PYPY3 verwendet wird: < /p>
In [2]: import sys, locale
In [3]: locale.getencoding()
Out[3]: 'utf-8'
In [4]: locale.getlocale()
Out[4]: ('English_United States', '1252')
In [5]: sys.getdefaultencoding()
Out[5]: 'utf-8'
Code: Select all
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" -Name "PYTHONIOENCODING" -Type STRING -Value "UTF-8"
< /code>
Im Folgenden funktioniert auch nicht: < /p>
chcp 65001
Code: Select all
PS C:\Users\xenig> [Console]::InputEncoding = New-Object System.Text.UTF8Encoding
PS C:\Users\xenig> [Console]::OutputEncoding = New-Object System.Text.UTF8Encoding
PS C:\Users\xenig> D:\Programs\pypy3\Scripts\ipython.exe
Python 3.11.11 (0253c85bf5f8, Feb 26 2025, 10:43:25)
Type 'copyright', 'credits' or 'license' for more information
IPython 9.0.2 -- An enhanced Interactive Python. Type '?' for help.
Tip: IPython 9.0+ have hooks to integrate AI/LLM completions.
In [1]: b'\xce\x9e\xce\xad\xce\xbd\xce\xb7 \xce\x93\xce\xae\xce\xb9\xce\xbd\xce\xbf\xcf\x82'.decode('utf8')
Out[1]: 'Ξένη Γήινος'
< /code>
Okay, jetzt wie kann ich es schaffen, damit ich PYPY3 in Windows Terminal direkt starten kann, ohne PowerShell zuerst zu starten und PYPY3 -Unicode -Zeichen richtig anzeigen?pypy win32 3.11.11 (0253c85bf5f8, Feb 26 2025, 10:43:25)
[PyPy 7.3.19 with MSC v.1941 64 bit (AMD64)]
os.device_encoding(0)='cp850'
os.device_encoding(1)='cp850'
sys.getdefaultencoding()='utf-8'
sys.getfilesystemencoding()='utf-8'
locale.getpreferredencoding()='utf-8'
locale.getencoding()='utf-8'
locale.getlocale()=('English_United States', '1252')
locale.getlocale()=('English_United States', '1252')