ModuleNotFoundError: No module named 'pgzrun' when I have it installed?

Viewed 8964

Why does IDLE say

ModuleNotFoundError: No module named 'pygame'

when I have it installed? I installed it with pip. I tried deleting the import but then IDLE gives me a name error saying pygame isn't defined.. I tried doing

import pygame

and

import pgzrun

and

import pgzero

here's my code where its used:

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

I also used a code editor called mu but then if I use functions, it gives me a name error.

4 Answers

Got to python/scripts path and try to uninstall it with python -m pip uninstall pygame then install it with python -m pip install pygame --user

When installing a python package without --user, pip defaults to installing it on the system directory such as /usr/local/lib/python3, and this requires root access. While when using --user, pip installs the package in your home directory which doesn't require any root access or special privileges. So that leaves us with two ways to install Pygame correctly, The first one is to use --user to install it without special privileges and the Second choice is to run the terminal as an administrator on Windows or as root on Linux to give it root access for it to download Pygame successfully.

It could be that your IDE is using a different version of Python than the one you installed the package to. Try the following to make sure that the package is installed to python 3:

pip3 install pygame

Some code editors require a restart when new packages are installed.

After installing the latest version of python3, do this:

python -m pip install pygame==1.9.6

This worked for me on macOS High Sierra and Windows 10

I think It was a comment somebody made saying it was a miss configured IDE.Now I use spyder 4 And it works fine.

september 17 : Now I figured out that it was actually my path was wrong

Related