Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compilation error. AttributeError: 'module' object has no attribute 'init'

Here is my small program,

import pygame
pygame.init()

Here is my compilation command.

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 this statements, It works fine.

like image 989
SunnyShah Avatar asked Oct 31 '10 23:10

SunnyShah


1 Answers

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

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

like image 103
Ned Batchelder Avatar answered Nov 02 '22 11:11

Ned Batchelder