'Cannot display emojis in Windows Powershell or WSL Linux Terminal using Python
I am trying to print emojis in both Windows Powershell and WSL Linux Terminal using Python3.
I have tried using unicode, CLDR names and also installed the emoji library.
print("\U0001F44D")
print(emoji.emojize(':thumbs_up:'))
But in the terminal it is showing only a question mark within a box. No emoji is showing.
What is the issue here?
But if I copy the output here it is showing properly. Like this 👍
Solution 1:[1]
I don't think any of the Windows Shells has proper support for emoji/unicode characters, or it may not support emojis.
If your using Windows, you may want to try Windows Terminal. It has complete Emoji support and should work with Powershell and WSL.
Solution 2:[2]
The issue is a shortcoming of both the Windows console and Powershell 5. They can both display some Unicode, but they don't have support for characters that are outside the Basic Multilingual Plane, which is where emojis lie. You can tell that from the nonzero 2nd byte in U0001F44D.
To illustrate the distinction, this is from Powershell, but you'll get identical results in the cmd.exe console:
PS C:\Users\boargules> python -c "print('\U0000201E')"
„
PS C:\Users\boargules> python -c "print('\U0001F44D')"
?
(The last line is SO's glyph for U+FFFD. Windows' glyph for U+FFFD is a bit different: the box around the question mark is a square not a lozenge.)
No amount of fiddling with the codepage (such as, for cmd.exe
: chcp 65001
) will fix this. The underlying reason is that these consoles don't fully support Unicode, they support its predecessor UCS-2, which is essentially UTF-16 but without support for characters outside the BMP.
Solution 3:[3]
Summary: Solved by using WSL terminal of Visual Code .
Details:
For me, I had the same issue.
It does not work with the default WSL terminal program:
But It does work with WSL terminal opened from Visual Code.
This is how you could open that terminal in Visual Code:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | sybrg |
Solution 2 | BoarGules |
Solution 3 | Abdennour TOUMI |