pythonmacosvisual-studio-codemodulepygame

Import "pygame" could not be resolved Pylance (reportMissingImports) error in VSCode on mac


import pygame

#initialise
pygame.init()

screen = pygame.display.set_mode((800, 600))

running = True
while running == True:
    for event in pygame.event.get():
        if event.type == pygame.quit:
            running = False

This code actually runs, but the error does not go away. I am following a pygame tutorial that uses pycharm. Is the issue the program I am using?

I'm a beginner and can't figure this out at all.


Solution

  • If you are using the global environment, you need to reopen the VSCode after you install the package you want to import.

    enter image description here

    If you are using the virtual environment, Plycance Language Server can detect the packages automatically after you installed them.

    enter image description here