Search code examples
pythonpygamepy2exe

"No module named pygame" on a python to exe file


I was testing pygame with auto_py_to_exe and it came up with this error:

Traceback (most recent call last):
  File "drawrect.py", line 1, in <module>
ModuleNotFoundError: No module named 'pygame'

Image:

Image

Code:

import pygame

Rect = pygame.Rect(0, 0, 150, 150)
Rect.center = (240, 240)
white = (255, 255, 255)
surface = pygame.display.set_mode((480, 480))

pygame.init()

while True:
    surface.fill((0, 0, 0))
    pygame.draw.rect(surface, white, Rect)
    pygame.display.update()


Solution

  • pip install pygame is the command you are looking for.

    Run this command in your terminal and then try again.