Using #-*- coding: utf-8 -*- does not remove “Non-

2019-03-01 11:19发布

I'm trying to convert a python file into an executable. So far so good. But when I try to run the executable I get the following error message:

SyntaxError: Non-ASCII character '\x90' in file hello.exe on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details"

This problem is widely documented, but using the given solution of adding

#-*- coding: utf-8 -*-

at the start of the line is not solving my issue.

I'm using Notepad++ editor and have even enforced the utf-8 encoding explicitly but to no avail.

Is there anything that I'm missing?

2条回答
该账号已被封号
2楼-- · 2019-03-01 12:05

As someone else mentioned, you are running "python hello.exe" or "py hello.exe". So you are trying to run an executable with python.. Try just running the executable without python.

You simply need to run "hello.exe".

查看更多
女痞
3楼-- · 2019-03-01 12:08

It seems you try to run your executable with

python hello.exe

while the point of creating an executable using py2exe is that you don't need to use the python interpreter anymore. So the error is actually not related to an encoding problem at all (though the error message might imply this) but just a consequence of calling python with a binary file.

查看更多
登录 后发表回答