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
1,466 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, 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 pygame.py 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
3,721 views
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
1,599 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,780 points
5,845 views
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 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,160 views
0 votes
0 answers
+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,810 points
1,627 views
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
18,752 views