So, I've recently installed pygame and every time I program with it in Visual Studio Code, the .py file runs fine. This is the thing, VSC underlines import pygame
with yellow, stating it's an error. It's annoying to me because I can't autofill ANY of the pygame functions. When I click "View Problem", it says "Import "pygame" could not be resolved." Yes, I've tried using venv.
Asked
Active
Viewed 841 times
0

MaxFlyMan
- 31
- 3
1 Answers
0
Make sure you have your init
function:
pygame.init()
If you haven't initialized pygame
, it's possible that VScode underlines it to warn you.
(Pylance)
You could also try to add ./sources
in the VScode settings:
(Pylint)
or go in your .vscode
folder in settings.json
. Under user settings paste this:
"python.linting.pylintArgs": [
"--extension-pkg-whitelist=pygame"
]

krmogi
- 2,588
- 1
- 10
- 26
-
I did "pygame.init()" already, it's still giving me that error. :/ – MaxFlyMan Oct 26 '21 at 00:06
-
Did you also try to add `./sources`? – krmogi Oct 26 '21 at 00:08
-
idk how to get to that :( – MaxFlyMan Oct 26 '21 at 00:10
-
Are you using pylint or pylance? – krmogi Oct 26 '21 at 00:15
-
yes, im using pylance – MaxFlyMan Oct 26 '21 at 00:17
-
`import pygame` would obviously have to come before `pygame.init()`, so I don't see how this could possibly solve an error with importing. – John Gordon Oct 26 '21 at 00:18
-
Ok, search up pylance in extensions, and then if you scroll down you should see a "Extra path setting". There, paste in `./sources`. – krmogi Oct 26 '21 at 00:19
-
okay I add ./sources and i went back to my code and "import pygame" is still underlined – MaxFlyMan Oct 26 '21 at 00:27
-
You may have to restart vscode – krmogi Oct 26 '21 at 00:28
-
theres still an error after restarting : – MaxFlyMan Oct 26 '21 at 00:30
-
pycharm seems to work so ¯\_(ツ)_/¯ – MaxFlyMan Oct 26 '21 at 01:23