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

前端 未结 14 1119
予麋鹿
予麋鹿 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:19

    This answer includes the answer to your question. In short it explains:

    Pylint imports modules to effectively identify valid methods and attributes. It was decided that importing c extensions that are not part of the python stdlib is a security risk and could introduce malicious code.

    and as a solution it mentions, among others:

    Disable safety using the .pylintrc setting unsafe-load-any-extensions=yes.

    See here for more information about pylint.rc. Quickest method is to just create the file .pylintrc in your project directory or your home directory.

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

    If you are using vscode then you can go to settings:

    python.linting.pylintEnabled = False
    

    It will fix the problem. If you aren't using vscode then you can go the command prompt and manually uninstall pylint with the command

    pip uninstall pylint. 
    
    0 讨论(0)
  • 2020-12-01 14:23

    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"
      ]
      
    0 讨论(0)
  • 2020-12-01 14:27

    I had the same issue with one of my modules. This is what I did to resolve the problem. (I'm using visual studio on windows 10)

    1. Press CTRL+SHIFT+P in visual studio
    2. Choose "Preferences: Open Settings (JSON)"
    3. Add "python.linting.pylintArgs": ["--generate-members"] below one of the lines (put a comma if necessary)
    4. Save the .json file (CTRL+S)

    For me, the code looks like this :

    {
        "breadcrumbs.enabled": false,
        "editor.minimap.enabled": false,
        "python.pythonPath": "C:\\Users\\xxx\\Anaconda3",
        "terminal.integrated.rendererType": "dom",
        "window.menuBarVisibility": "default",
        "workbench.activityBar.visible": false,
        "workbench.statusBar.visible": true,
        "python.linting.pylintArgs": ["--generate-members"], //line to add
        "[json]": {
    
        }
    }
    

    Hope it helps. Credit to @Alamnoor on github

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

    I recommend going to the view tab, clicking command palette and searching preferences: open settings.json. Then add a comma on the last line of code.Below that paste this:

    "python.linting.pylintArgs": [
        "--extension-pkg-whitelist=extensionname" // comma separated
    ]
    

    Then save your document (ctrl + s).

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

    Disable Pylint 1.Press ctrl + shift + p 2.Then type Disable Pylint

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