python - 编译错误。属性错误 : 'module' object has no attribute 'init'

标签 python compiler-errors

这是我的小程序,

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/

相关文章:

python - 计算 pandas 中分组的行差异

ios - “No known class method for selector ' validSuits xCode 5.1中的'”错误

Java "Reached end of file while parsing"

ios - 错误消息 "Parse Issue Expected identified or ‘(‘ "

c++ - 优先队列编译错误

c++ - 无法在赋值中将 'int*' 转换为 'ABC*'

python - 在蝗虫中如何从一个任务获得响应并将其传递给其他任务

python - 请求与重定向发生奇怪的交互

python - 将输入字符串转换为可调用函数并将其存储为变量的正确方法?

python - 从多个数据框中删除多列