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, 2019 in Python by Harsha
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, 2019 by Varsha
that doesn't work; it won't destroy the error. it's a problem of python thinking that pygame.locals isn't even a thing.

HI, @There,

My guess is that you have a file named in the current directory in which you are running your script.

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, 2019 in Python by Greg
0 votes
1 answer
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
+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
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,181 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
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, 2019 in Python by Hari
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP