Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SyntaxError: Non-UTF-8 code starting with '\xfe'

Tags:

python

Here is my code and it looks fine.

import ael

while True:
    cmd = input('AEL > ')
    result, error = ael.run(cmd)

    if error: print(error.as_string())
    else: print(result)

But whenever I run it, wether it's from PyCharm (my IDE) or from the terminal, I always get the following error: SyntaxError: Non-UTF-8 code starting with '\xfe' in file C:\Users\[...] on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

Here is what I have tried in an attempt to solve this issue:

  • Adding # coding=utf-8 at the start of the program
  • Adding # -*- coding: utf-8 -*- at the start of the program

How would I solve this issue? Any potential solutions?

like image 660
GGberry Avatar asked Sep 22 '26 07:09

GGberry


1 Answers

This happens sometimes because the file does not include the Byte Order Mark - BOM. Using IntelliJ IDEA (or any other JetBrains IDE) I solved the problem by adding the BOM through the encoding menu on the left bottom corner of the window:

Add BOM

You can do the same with any text editor that supports adding and removing BOM.

like image 140
Hamza Abbad Avatar answered Sep 25 '26 16:09

Hamza Abbad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!