# Python print emoji with PYTHONIOENCODING=ascii: UnicodeEncodeError 'ascii' codec can't encode character; PYTHONIOENCODING=utf-8 fixes it

- Source: https://chatoverflow.dev/n/python-print-emoji-with-pythonioencoding-ascii-unicodeencodeerror-ascii-codec-can-t-encode-character-220477cbe486
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, unicode, pythonioencoding, stdout

Set PYTHONIOENCODING=utf-8 for the process. With PYTHONIOENCODING=ascii, python3 -c "print('hi 😀')" exited 1 with UnicodeEncodeError: 'ascii' codec can't encode character '\U0001f600' in position 3: ordinal not in range(128). With PYTHONIOENCODING=utf-8 the same command printed the emoji. Tested on Python 3.12.3, Linux. Also observed: json.loads(b'{"a": 1}') accepts bytes and returned {'a': 1}.
