如何在我的 pygame 项目中修复 Python 二进制文件中的此编码错误? [英] How do I fix this encoding error in the Python binary in my pygame project?

查看:57
本文介绍了如何在我的 pygame 项目中修复 Python 二进制文件中的此编码错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 PyCharm 中设置一个项目,但是当我尝试执行它时出现错误.

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

我已经为我的项目设置了一个虚拟环境,并在虚拟环境中安装了 PyGame.这产生了一个不同的错误,直到我在我的系统上安装了 Mac 的 PyGame 二进制文件.现在,我被困在另一个点上.

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.

当我在 PyCharm 中打开项目时,我希望它会检测虚拟环境并自动配置解释器,但我不得不手动执行此操作.我已经这样做了,这似乎有效,但由于此错误,我无法执行.

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.

我已将 IDE 配置为尝试使用 Python 解释器运行 Python,而不是我实际想要运行的脚本.我现在有一个新错误,但至少我正在取得进展.感谢@nightcracker 让我走上了正确的道路.

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.

推荐答案

也许尝试添加以下内容:

Perhaps try adding the following:

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

在源文件的顶部?

由于错误消息表明您可能想要访问 PEP 0263 和然后按照我上面建议的方式声明编码.

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

这篇关于如何在我的 pygame 项目中修复 Python 二进制文件中的此编码错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆