0

i'm using python 2.7 32-bit windows and pygame 1.9.1

import pygame, sys
from pygame.locals import *

pygame.init()
DISPLAYSURF = pygame.display.set_mode((400, 300))
pygame.display.set_caption('Hello World!')
while True: # main game loop
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
    pygame.display.update()

And the error message is:

Traceback (most recent call last):
  File "C:/Python27 32bit/Scripts/test.py", line 1, in <module>
    import pygame
  File "C:/Python27 32bit/Scripts\pygame.py", line 2, in <module>
ImportError: No module named locals
  • 2
    don't use `pygame` as your script name because `import pygame` will try to import your script instead of oryginal `pygame` module. – furas Dec 19 '15 at 15:52
  • 2
    Where is `image.load(arduino)`? – Padraic Cunningham Dec 19 '15 at 16:01
  • did you rename `C:/Python27 32bit/Scripts\pygame.py` into something different ? – furas Dec 19 '15 at 16:10
  • import pygame, sys from pygame.locals import * pygame.init() DISPLAYSURF = pygame.display.set_mode((400, 300)) pygame.display.set_caption('Hello World!') while True: # main game loop for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() pygame.display.update() – user5698459 Dec 19 '15 at 16:13
  • Please add additional code to your question instead of the comments. Thank you. – OneCricketeer Dec 19 '15 at 16:14
  • is this code in `pygame.py` ? don't use name `pygame.py` because `import pygame` first try import local file `pygame.py` instead of original `pygame` module. – furas Dec 19 '15 at 16:15
  • thats why i made a new one with the same code – user5698459 Dec 19 '15 at 16:17
  • @furas - I see what you are saying, but are you ignoring the fact that it says `image` is not defined and OP has not imported `pygame.image`? – OneCricketeer Dec 19 '15 at 16:18
  • did you delete `pygame.py` file ? if you don't then `import pygame` will import this local file instead of module. – furas Dec 19 '15 at 16:18
  • and what error message you have now - add it to question. – furas Dec 19 '15 at 16:23
  • @cricket_007 I think main problem is local file `pygame.py` - it have to be deleted. – furas Dec 19 '15 at 16:26
  • i have deleted the pygame.py file – user5698459 Dec 19 '15 at 16:28
  • My question is why are you writing code in the `C:\Python2.7 32bit` directory? You could really damage your Python installation by messing around in there. You can run your python code from anywhere on your computer – OneCricketeer Dec 19 '15 at 16:29
  • thanks cricket_007 you solved the problem it works now – user5698459 Dec 19 '15 at 16:33
  • @cricket_007 Please don't answer the question in comments. It creates clutter on the unanswered questions list. – pppery Dec 27 '15 at 17:09
  • @ppperry - I don't even know what the solution here was. I was making suggestions, not answering – OneCricketeer Dec 27 '15 at 19:07

0 Answers0