0

I'm having an error while using Pygame. I'm using Python 3.5 and Pygame 3.2. I started to learn Pygame just today and it gives me this error:

Code:

import pygame

pygame.init()
width, height = 640, 480
screen=pygame.display.set_mode((width, height))

player = pygame.image.load("resources/images/dude.png")


while 1:
    screen.fill(0)
    screen.blit(player, (100,100))
    pygame.display.flip()

    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            pygame.quit() 
            exit(0)

ERROR:

Traceback (most recent call last):
File "test.py", line 5, in <module>
pygame.init()
AttributeError: module 'pygame' has no attribute 'init'
2
  • 5
    Possible duplicate of Pygame attribute, init() Commented Jul 11, 2016 at 13:59
  • 1
    How did you install pygame? This answer may help. Another possibility is that you have a script named pygame.py in the directory you're running test.py from (or elsewhere in your PYTHONPATH) that's shadowing the real pygame module. Commented Jul 11, 2016 at 13:59

2 Answers 2

0

try moving your pygame folder in the same file where this code is, and delete or move any other file named pygame.py If neither of that works, try cleaning your python folders by uninstalling and installing python. Then install pygame by doing the following:

1.) go to: This website and download the correct version of pygame

2.) move the download to your python - scripts folder

3.) then highlight the download and shift - right click on an empty space in the file explorer

4.) select: open command window here

5.) type in : pygame.install.(download name)

where download name is type in the name of the pygame you downloaded( you can just type in pygame and press tab for short)

Sign up to request clarification or add additional context in comments.

Comments

-1

Delete the "pygame.py" file in your Documents folder, it is shadowing the real pygame you've installed.

1 Comment

I have no pygame.py file in my documents folder nor any other folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.