0

I am learning python on my raspberry pi 3, so I thought that I would try to add some graphics. I was trying to bring up a window to add my graphics on, but it brings up the following error message:

Traceback (most recent call last):
  File "/home/pi/python_programmes/pygame1.py", line 1, in <module>
    import pygame
  File "/home/pi/python programmes/pygame.py", line 6, in <module>
AttributeError: 'module' object has no attribute 'init'

The code that I entered is:

import pygame
pygame.init()
size = [700, 500]
screen = pygame.display.set_mode(size)
pygame.display.set_caption("My game")
done = False
clock = pygame.time.Clock()
while done == False:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True
    clock.tick(20)
pygame.quit()

I deleted all files that where called pygame.py, but there is still one that is called pygame.pyc

Andrew Bell
  • 23
  • 2
  • 7
  • 1
    Possible duplicate of [i keep getting the error 'module' object has no attribute 'init'](https://stackoverflow.com/questions/28231200/i-keep-getting-the-error-module-object-has-no-attribute-init) – skrx Apr 02 '18 at 12:22
  • @skrx It isn't, as I tried what it says in the question, and called it something that is no pygame.py, and it still comes up with the same error message – Andrew Bell Apr 02 '18 at 12:28

1 Answers1

1

you have a local file named File "/home/pi/python programmes/pygame.py" , so what happens is your script not importing pygame library rather it is importing pygame.py from your local folder File "/home/pi/python programmes/" . your just need to rename this file from pygame.py to something else and your issue is fixed.

toheedNiaz
  • 1,435
  • 1
  • 10
  • 14