我不断收到错误的“模块"对象没有属性“初始化" [英] i keep getting the error 'module' object has no attribute 'init'

查看:116
本文介绍了我不断收到错误的“模块"对象没有属性“初始化"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尤其是当我从外部python文件运行它并仅使用IDLE或Pycharm运行它时.我只输入了

Especially when i run it from an external python file and just run it using IDLE or Pycharm..Please Help...but at times it works with in the interactive shell and then something happens and it starts its problems ....I simply typed

import pygame
x = pygame.init()
print(x)

C:\ Python33 \ python.exe C:/Users/Home/Desktop/pygame.py追溯(大多数 最近通话结束):文件"C:/Users/Home/Desktop/pygame.py",第1行 在 在第2行中导入pygame文件"C:\ Users \ Home \ Desktop \ pygame.py" x = pygame.init()AttributeError:模块"对象没有属性"init"

C:\Python33\python.exe C:/Users/Home/Desktop/pygame.py Traceback (most recent call last): File "C:/Users/Home/Desktop/pygame.py", line 1, in import pygame File "C:\Users\Home\Desktop\pygame.py", line 2, in x = pygame.init() AttributeError: 'module' object has no attribute 'init'

以退出代码1完成的过程.

Process finished with exit code 1.

推荐答案

问题是您将文件命名为pygame.py.

The problem is that you named your file pygame.py.

如果您运行它并想导入pygame,它将导入您的文件C:\Users\Home\Desktop\pygame.py,而不是已安装的pygame模块.

If you run it and you want to import pygame, it will import your file C:\Users\Home\Desktop\pygame.py and not the installed pygame module.

因此,只需使用另一个文件名(并删除C:\Users\Home\Desktop\pygame.py和任何其他剩余的内容)即可.

So just use another filename (and delete C:\Users\Home\Desktop\pygame.py and any other leftovers).

这篇关于我不断收到错误的“模块"对象没有属性“初始化"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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