简体   繁体   中英

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.

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

在此处输入图像描述

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

在此处输入图像描述

@eklavyaisabird - I have faced same issue on VSCode but I had added ./sources on Pylance extra path setting, it fixed the error

在此处输入图像描述

After adding it to the environment using pycharm, it somehow fixed the issue in VSCode as well. Weird. I wonder how I would do the same thing with only vscode.

After a long time trying to solve the problem, I had to manually add the library folder in Pylance. enter image description here

It may be that the location of your libraries is in a different place, but after the Python folder the location doesn't change (unless you changed it yourself), in my case it still didn't work, if yours doesn't work either, put: C:\python\python310\lib\site-packages\pygame If you installed without making any changes your python folder is in c:\Users\Your user\AppData\Roaming\Python...

I have experienced the same problem on VSCode even though the package was already there using pip install pygame and I had to add the library folder in Pylance manually, I copied the library path and pasted it to Pylance extra path setting. It solved my problem. Pylance extra path setting

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM