i keep getting the error 'module' object has no attribute 'init'

醉酒当歌 提交于 2019-11-28 02:18:12

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

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.

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

pygame.init() initializes the pygame module, you don't assign it as a variable.

import pygame
pygame.init()

And that's it.

edit: As sloth mentioned: you also don't name your python projects the same name as modules, especially if you plan on importing them.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!