Error: Module 'pygame' has no 'init' member

Error: Module 'pygame' has no 'init' member

我正在使用 VS Code,当我使用 pygame.init() 时出现此错误:

Module 'pygame' has no 'init' member

我尝试在设置中将 --extension-pkg-whitelist=pygame 添加到 python.linting.pylintArgs 并且错误停止了,但随后我的几乎所有代码都变成了蓝色并提示这些错误:

Constant name "grid1" doesn't conform to UPPER_CASE naming stylepylint(invalid-name)

编辑: 所以这是一个 linter 警告,我想删除但是当我尝试使用上面的方法时,所有内容下面都有一条蓝线。

我的 OS 是 Windows 10,我使用的是最新的 python 版本和最新的 pygame 版本。

您正在被这些错误轰炸,因为您的代码可能不符合 PEP8 编写风格 Python 代码。

右键单击文件中的任意位置,然后单击 Format Document 或按 Alt+Shift+F 以自动设置代码格式。之后,只需查看剩余的警告和错误并尝试修复它们。错误可能只是要求您为函数和 类.

制作文档字符串

如果您不想编写文档字符串,请将其添加到您的 VSCode settings.json 文件中

"python.linting.pylintArgs": [
    "--disable=C0114, C0116",
],