How to get certain pygame modules to work in VSC?, other fixes not working

Viewed 59

im having trouble right now, using latest python and vsCode. i keep getting "module pygame has no BLANK member Pylint no-member" for different pygame functions im using. K_a, K_s, K_d, K_f and those controls work fine in the game, but ones like QUIT and KEYDOWN and LCTRL and RCTRL just crash the game. VSC says module pygame has no member for ANY of them, even the ones that work. But it crashes when i try LCRTL or such.

My understanding is that it is a security function where Pylint is blocking certain pygame modules but im not sure, ive found a couple similar problems where people are suggesting adding ""python.linting.pylintArgs": [ "--extension-pkg-whitelist=pygame" and others to the settings.json file. But i have tried these and it still doesnt work! I also tried adding a import all pygame modules line and tried adding the pygame modules individually but nothing is working. Please help.

Also, idk if it helps, but when i hover over any of my pygame modules such as K_a or K_LCRTL they show up as integers and not as a special pygame module. They arent even highlighted they just look like regular text.

edit: maybe worth noting that VSC even knows they are pygame controls because when i type them it will even auto-fill them in for me. I think its just pylint blocking certain ones. but like i said all of them show up as "not a pygame member, pylint non-member) and also i dont have any files named game or pygame or anything thats messing with it.

1 Answers

Pylint only analyse your code and cannot prevent access to a lib during its execution. If there is an import error during execution it means the import was wrong for this particular version of pygame, whatever pylint says about it. If the code works it means pylint is mistaken about the import being wrong.

To be more precise, pylint do not load code inside C-binding by default. Pygame has c-binding, so it means pylint can't check the import correctly on those, and say there is no member when it fact it works because of C code pylint can't analyse.

Adding pygame in your extension-pkg-whitelist is actually what you have to do in this case.

# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code
extension-pkg-whitelist=pygame

But at the end of the day pylint can makes mistakes and if the import really is bad you need to fix those after testing yourself by launching the code or disable pylint check if the import is okay with # pylint: disable=no-member.

Related