Why does it say that module pygame has no init member? Why does it say that module pygame has no init member? python python

Why does it say that module pygame has no init member?


If you have VS code, go in your .vscode folder > settings.json or search for python.linting.mypyArgs Under user settings tab paste inbetween curly braces

"python.linting.pylintArgs": [    "--extension-pkg-whitelist=lxml"  // The extension is "lxml" not "1xml"]

I no longer see the pyinit error.


Summarizing all answers.

This is a security measure to not load non-default C extensions.

  1. You can white-list specific extension(s).

    Open user settings and add the following between {}:

    "python.linting.pylintArgs": [    "--extension-pkg-whitelist=extensionname" // comma separated]
  2. You can allow to "unsafe load" all extensions.

    Open user settings and add the following between {}:

    "python.linting.pylintArgs": [    "--unsafe-load-any-extension=y"]


I had the same issue when I started using Visual Studio Code with Python. It has nothing to do with having another pygame.py or not installing it properly. It has to do with the fact that Visual Studio Code takes your code literally, and since you cannot import pygame.init(), it thinks that it isn't a correct module.

To fix this, open up settings.json (go into your settings, and click the {} icon) and paste

"python.linting.pylintArgs": [    "--extension-pkg-whitelist=pygame"]

to it.