How do I fix this encoding error in the Python bin

2019-07-30 05:29发布

I'm trying to setup a project in PyCharm, but I get an error when I try to execute it.

SyntaxError: Non-ASCII character '\xca' in file /Users/raddevon/PycharmProjects/pygame/env-pygame/bin/python on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

I've setup a virtual environment for my project and have installed PyGame in the virtual environment. This generated a different error until I installed the PyGame binaries for Mac on my system. Now, I'm stuck at another point.

When I opened the project in PyCharm, I expected it would detect the virtual environment and configure the interpreter automatically, but I had to do this manually. I have done so and that seemed to work, but I am unable to execute due to this error.

EDIT: I had configured the IDE to try running Python with the Python interpreter rather than the script I actually wanted to run. I've got a new error now, but at least I'm making progress. Thanks to @nightcracker for setting me on the right path.

1条回答
三岁会撩人
2楼-- · 2019-07-30 05:55

Perhaps try adding the following:

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

at the top of your sourcefiles?

As the error message suggests you may want to visit PEP 0263 and then declare the encoding as I proposed above.

查看更多
登录 后发表回答