Package installed but still says "ImportError: No module named pygame.locals"

0 votes

I have been getting this error while trying to make a game using pygame.

ImportError: No module named pygame.locals

This thread says that I need to install that module. And I followed those and steps and installed it. In fact, I even got an installation success message. But when I try to run the code again, I still get the same error.

What is the issue?

Jun 18 in Python by Harsha
86 views
Can you show your initial part of the code?
from pygame.locals import *
import pygame

class Player:
    x = 10
    y = 10
    speed = 1

    def moveRight(self):
        self.x = self.x + self.speed

    def moveLeft(self):
        self.x = self.x - self.speed

    def moveUp(self):
        self.y = self.y - self.speed

    def moveDown(self):
        self.y = self.y + self.speed

1 answer to this question.

0 votes

So Harsha, you Import the module first and then use it. Change the first two lines. 

import pygame
from pygame.locals import *

This should eliminate the error

answered Jun 18 by Varsha

Related Questions In Python

0 votes
1 answer

Python error "ImportError: No module named pygame.locals"

You need to download and install the ...READ MORE

answered Jun 18 in Python by Greg
72 views
0 votes
1 answer

ImportError: No module named requests

Requests is not available for use by ...READ MORE

answered Jun 26, 2018 in Python by Hamartia's Mask
• 1,580 points
615 views
+3 votes
1 answer

Tensorflow 1.5 ImportError: No module named tensorflow.python.client

I think it's a bug in Tensorflow ...READ MORE

answered Sep 25, 2018 in Python by charlie_brown
• 7,720 points
2,235 views
0 votes
1 answer

tensorflow 1.5 ImportError: No module named tensorflow.python.client

Some of the modules have changed in ...READ MORE

answered Oct 5, 2018 in Python by Priyaj
• 56,520 points
451 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 170 views
+4 votes
6 answers
0 votes
1 answer
0 votes
1 answer

Python: ImportError: No module named Crypto.Cipher

Seems like the pycrypto package is not ...READ MORE

answered Jul 31 in Python by Hari
51 views