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

后端 未结 3 1178
迷失自我
迷失自我 2021-01-12 01:30

Here is my small program,

import pygame
pygame.init()

Here is my compilation command.

python myprogram.py

相关标签:
3条回答
  • 2021-01-12 02:00
    1. Here is my compilation command:python myprogram.py but you have error in File "game.py", line 1, in oO

    2. I was have same problem and solve it by renaming of main .py file. He can't be the same as module i.e pygame

    0 讨论(0)
  • 2021-01-12 02:01

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

    import pygame
    from pygame.locals import *
    pygame.init()
    
    0 讨论(0)
  • 2021-01-12 02:09

    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".

    0 讨论(0)
提交回复
热议问题