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

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

问题描述

这是我的小程序,

  import pygame 
pygame.init()

这里是我的编译命令。


python myprogram.py


错误,

 
文件game.py,第1行,在
中import pygame
文件/ home / ubuntu / Documents / pygame.py,第2行,在
中pygame.init()
AttributeError:'module'对象没有属性'init'

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

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

我从IDLE中发现了tht,如果我执行

解决方案

删除文档文件夹中的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天全站免登陆