'Pygame is not defined error?

I'm having trouble with my .py program. At first, whenever I ran the program it displayed "object missing attribute init()". I moved my pygame file to the desktop folder and now it's displaying "pygame is not defined".

Traceback (most recent call last):
  File "C:\Users\Alex\Desktop\pygames.py", line 24, in <module>
    screen = pygame.display.set_mode(size)
NameError: name 'pygame' is not defined

Does anyone know what I'm doing wrong?



Solution 1:[1]

Try importing pygame, if you haven't installed pygame u can go type npm install pygame in terminal or vscode if thats what you use

Solution 2:[2]

I had a similar error, what you need to do is to change the name of the file to something other than pygame.py, sorry if it doesn't work

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 cluhap15
Solution 2 Paora