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

前端 未结 14 1120
予麋鹿
予麋鹿 2020-12-01 13:57

This is the code I have:

import pygame
pygame.init()

I\'m very confused because if I try to run the file, then there seems to be no issue,

相关标签:
14条回答
  • 2020-12-01 14:31

    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.

    0 讨论(0)
  • 2020-12-01 14:31

    I find an answer and it really works for me. See the accepted answer and change it to extension-pkg-whitelist=lxml

    pylint 1.4 reports E1101(no-member) on all C extensions

    0 讨论(0)
  • 2020-12-01 14:33

    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.

    0 讨论(0)
  • 2020-12-01 14:35

    Check if you have a python file named pygame.py created by you in your directory. If you do, then the import pygame line is importing your own file instead of the real Pygame module. Since you don't have an init() function in that file, you're seeing this particular error message.

    0 讨论(0)
  • 2020-12-01 14:39

    I found adding this in settings.json() solves the problem.

    "python.linting.pylintArgs":[
                "--extension-pkg-whitelist=pygame",
                "--erros-only"
          ]
    
    0 讨论(0)
  • 2020-12-01 14:41

    I found a solution, modifying the most voted answer:

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

    Replaced the "lxml" with "pygame".

    0 讨论(0)
提交回复
热议问题