Collection error. AttributeError: object 'module' does not have attribute 'init'

Here is my little program,

import pygame pygame.init() 

Here is my compilation team.

python myprogram.py

Compilation error,

  File "game.py", line 1, in 
     import pygame
   File "/home/ubuntu/Documents/pygame.py", line 2, in 
     pygame.init ()
 AttributeError: 'module' object has no attribute 'init'

I have pygame installed in my ubuntu, it is installed in

 /usr/lib/python2.6/dist-packages/pygame 

I found tht from IDLE, if I execute both of these statements, it works fine.

+6
python compiler-errors
source share
3 answers

Delete the pygame.py file in the Documents folder, it will obscure the real pygame that you installed.

It looks like you first saved a small test program as "pygame.py" and then renamed it to "game.py".

+12
source share
  • Here is my compilation command: python myprogram.py but you have an error in File "game.py", line 1, in oO

  • I had the same problem and solved it by renaming the main .py file. It cannot be the same as the pygame module

0
source share

Rename pygame.py to another_name_as_pygame.py and this is your new code:

 import pygame from pygame.locals import * pygame.init() 
-2
source share

All Articles