编译错误.AttributeError: 'module' 对象没有属性 'init' [英] compilation error. AttributeError: 'module' object has no attribute 'init'

查看:24
本文介绍了编译错误.AttributeError: 'module' 对象没有属性 'init'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的小程序,

导入pygamepygame.init()

这是我的编译命令.

<块引用>

python myprogram.py

编译错误,

<前>文件game.py",第 1 行,在导入pygame文件/home/ubuntu/Documents/pygame.py",第 2 行,在pygame.init()AttributeError: 'module' 对象没有属性 'init'

我在我的 ubuntu 中安装了 pygame,它安装在

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

我从 IDLE 中发现,如果我执行这两个语句,它工作正常.

解决方案

删除 Documents 文件夹中的pygame.py"文件,它隐藏了您安装的真实 pygame.

看起来您首先将您的小测试程序保存为pygame.py",然后将其重命名为game.py".

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.

解决方案

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

这篇关于编译错误.AttributeError: 'module' 对象没有属性 'init'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆