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?

5
  • 1
    Its possible that the text editor you're using is not encoding in utf-8. Commented May 26, 2020 at 21:36
  • 2
    You've probably saved the file as UTF-8 from an editor that puts a BOM at the front. Commented May 26, 2020 at 21:36
  • P.S. Did you read the PEP that the error pointed you to? Commented May 26, 2020 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. Commented May 26, 2020 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). Commented May 27, 2020 at 23:48

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.