2

I'm following Python's Packaging Projects tutorial and when it tells to run python3 setup.py sdist bdist_wheel I receive the following error:

PS C:\Users\username\dev\packaging_tutorial> python setup.py sdist
 bdist_wheel
  File "setup.py", line 1
SyntaxError: Non-UTF-8 code starting with '\xff' in file setup.py on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

I have no idea why I get this error since my setup.py file is identical to theirs. Has anyone had the same problem?

Gammaliel
  • 21
  • 1
  • 5
  • 1
    Its possible that the text editor you're using is not encoding in utf-8. – Ahmet May 26 '20 at 21:36
  • 2
    You've probably saved the file as UTF-8 from an editor that puts a BOM at the front. – Mark Ransom May 26 '20 at 21:36
  • P.S. Did you read the PEP that the error pointed you to? – Mark Ransom May 26 '20 at 21:38
  • 2
    But then it wouldn't be _non-UTF-8_ because the BOM is always a zero width no-break space in the respective encoding, so in UTF-8 it would be a _UTF-8 encoded_ zero width no-break space. In fact, a UTF-8 BOM would be `EF BB BF` (which doesn't contain `FF`). Sounds more like UTF-16 or UTF-32. – CherryDT May 26 '20 at 21:39
  • I'm sorry for the delay in my response, I use VS Code and as far as I know it is using whatever encoding is the default (I believe it is UTF 8). – Gammaliel May 27 '20 at 23:48

1 Answers1

3

You are getting this error since the file is created with the default encoding type of powershell, Windows-1252. You'll have to change the encoding type of the file to UTF-8, which python can recognize as python executable. You can achieve this by using the command chcp 65001

lonedalek
  • 39
  • 2
  • a \xff byte is unlikely to indicate Windows-1252 encoding, because in that encoding it means `ÿ`. It is very likely to indicate UTF-16, when reported (as here) in line 1, because a byte-order mark encoded in UTF-16 will include such a byte (regardless of endianness). – Karl Knechtel Mar 30 '23 at 11:30