I'm trying to run a simple Python code in VS Code that runs successfully in the terminal but throws an error in the output tab.
import emoji
print(emoji.emojize('I :red_heart: Python!'))
This is the terminal result:
>>> import emoji
>>> print(emoji.emojize('I :red_heart: Python!'))
I ❤️ Python!
This is the error shown in the Output tab of VS Code once I run the code:
Traceback (most recent call last):
File "c:\Users\subhr\OneDrive - University of St. Thomas\Python Practice\emoji_demo.py", line 3, in <module>
print(emoji.emojize('I :red_heart: Python!'))
File "C:\Python\Python310\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 2-3: character maps to <undefined>
I'm using the Code Runner for Visual Studio Code extension.
UTF-8in the bottom right of the vscode windowprint(b'I \xe2\x9d\xa4\xef\xb8\x8f Python!'.decode('utf-8'))? It should give the same result. If this works, the problem was in your file encoding. If this doesn't work, the problem is in your output terminal and you should search how to change the character encoding for that terminal.cp1252. As it's mentioningFile "C:\Python\Python310\lib\encodings\cp1252.py"in your error