Reputation: 1632
I am new to python and want to make a game in pygame. I have looked online and everyone says do this first:
import pygame
from pygame.locals import *
However, the shell window says:
Traceback (most recent call last):
File "...", line 2, in <module>
from pygame.locals import *
ImportError: No module named 'pygame.locals'
I am new so I have no idea why this works for others. Maybe I haven't installed something. Please tell me what. I am using python 3.4.0 and it is on a Ubuntu computer 14.04.
Thank you.
Upvotes: 0
Views: 3326
Reputation: 537
I had the same situation, and essentially C. McCarthy is right. First you need to rename any files in the working directory called 'pygame.something'. Then you need to remove any remaining files named 'pygame.something' from your working directory. (Alternatively you could also move to another, fresh directory and try there.)
If you think you HAVE removed everything then you should also check for pygame.pyc and pygame.py~ (maybe others as well, but these were the ones I had) both of which are hidden and won't turn up under normal conditions.
To look for these you can type into the terminal (whilst in the directory in question):
ls pygame.*
which will show all the filenames that contain 'pygame.' . If there are any, you can remove them with,
rm pygame.*
This all worked for me, and I am running Ubuntu 14.04
Upvotes: 0
Reputation: 102
Saw something similar to this, hope this helps
Your problem is that in that that current directory you have a file names pygame.py
, or a bytocode left-over from such a file named pygame.pyc
.
Meaning when you call pygame it will work but never actually import pygame, but the pygame file you have left. And since your file can't find a module named locals
in that file, the error is raised.
So, just rename your file to anything other than pygame.py
or other names of modules you want to import, or if you do have a pygame.pyc
bytecode file, remove that.
Upvotes: 1