这是我的小程序,
import pygame
pygame.init()
这是我的编译命令。
python myprogram.py
编译错误,
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
我从 IDLE 中发现,如果我执行这两个语句,它工作正常。
最佳答案
删除 Documents 文件夹中的“pygame.py”文件,它会隐藏您安装的真实 pygame。
看起来您首先将您的小测试程序保存为“pygame.py”,然后将其重命名为“game.py”。
关于python - 编译错误。属性错误 : 'module' object has no attribute 'init' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4065800/