[Python](EN) "SyntaxError: Non-ASCII character ..., but no encoding declared" related issue solution

Solution for “SyntaxError: Non-ASCII character …, but no encoding declared”

Environment and Prerequisite

  • Python

Problem and Solution


  • Error comes out like below when running python code.
python /home/twpower/MailReminder/reminder.py
SyntaxError: Non-ASCII character '\xeb' in file /home/twpower/MailReminder/reminder.py on line 12, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details


  • Issue which there was non ascii character in running code but encoding was not declared


  • Add # -*- coding: utf-8 -*- to top of python code file.
# -*- coding: utf-8 -*-