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

前端 未结 14 1182
予麋鹿
予麋鹿 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.

提交回复
热议问题