2

Hello i just started to learn python yesterday and today the guy in the video just started with

print("hello")

Then he executed it without a problem, but when I try to do it, I got the following error message :

SyntaxError: Non-UTF-8 code starting with '\xff' in file c:/Users/user/desktop/anan_bruh/bune.py on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

Littm
  • 4,923
  • 4
  • 30
  • 38
Kutay
  • 21
  • 2
  • 1
    Your file doesn't seem to be a valid Python file. – Klaus D. May 09 '20 at 23:37
  • This is likely an issue caused by your text editor. What are you editing the file with? Notepad.exe? There's probably a way to get it to write the file in a more sane encoding (e.g. without byte-order marks), but using a better text editor is probably something you'll want to do eventually anyway! – Blckknght May 09 '20 at 23:42
  • i am using microsoft visual code and i also installed the python extension too. this is the full error that i am getting PS C:\Users\ferat\desktop\anan_bruh> & C:/Users/ferat/AppData/Local/Programs/Python/Python38-32/python.exe c:/Users/ferat/desktop/anan_bruh/bune.py File "c:/Users/ferat/desktop/anan_bruh/bune.py", line 1 SyntaxError: Non-UTF-8 code starting with '\xff' in file c:/Users/ferat/desktop/anan_bruh/bune.py on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details – Kutay May 09 '20 at 23:44

1 Answers1

1

You need to ensure that your file is saved as an "ASCII" format.

If you are using windows, try using a program such as notepad++ or PFE or any other "text editing" program and ensure that the save file type is ASCII, ANSI, Latin or UTF-8.

If you are using Windows notepad, do not save the file as UTF-16. You can set the Encoding when you "Save as...". See the screen shot below:

enter image description here

If you are using Microsoft word or write or some other type of "word processor" - the easiest solution is don't do that! Instead, use notepad, PFE, Notepad++ or any of the hundreds of other "text editing" programs available online.

I hope this helps you.

I just saw the additional comment about using Visual Studio. I do not have that setup, but nevertheless the answer is the same. If I save my little "hello world" script using UTF-16, then I get the exact same error as you.

If I save my file as ANSI or UTF-8, the error is resolved. No doubt there is a way to save the files with the correct encoding within Visual Studio, but maybe try my answer first, verify that the solution works and then try to figure out how to do the same thing in Visual Studio.

GMc
  • 1,764
  • 1
  • 8
  • 26