简体   繁体   中英

Why do I get this No module named 'pygame in Spyder even after installing pip intall pygame?

I'm a very beginner python programmer. I installed pygame however when I import pygame in spyder, it doesn't work. pip install pygame

The following message prompts. ModuleNotFoundError: No module named 'pygame'

Below is what I wrote so far

import pygame

WIDTH, HEIGHT = 900, 500 WIN = pygame.display.set_mode((WITH, HEIGHT))

def main():

run = True

while run:
    
    for event in pygame.event.get():
        #end this while loop
        if event.type == pygame.QUIT:
            run = False
pygame.quit()

Try

py -m pip install pygame
or

python3 -m pip install pygame

Maybe you're a user on your computer without elevated privileges which belong to the admin. If the prompt showed an error while installing pygame, it means you do not have the required permissions.
Try to install pygame with the pip install --user pygame

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