Pygame attribute, init()

久未见 提交于 2019-11-28 14:09:28

You have a directory named pygame in your path somewhere.

$ mkdir pygame  # empty directory
$ python3.3
>>> import pygame
>>> pygame
<module 'pygame' (namespace)>
>>> pygame.__path__
_NamespacePath(['./pygame'])

Remove or rename this directory, it is masking the actual pygame package.

If you use print(pygame.__path__) it'll tell you where the directory was found; in the above example it was found relative to the current directory (./).

After import pygame pygame.init()

I got this error message and programm didnt work: " AttributeError: module 'pygame' has no attribute 'init' "

because i named the file "pygame.py"...

When i chaned filename to "pygametest.py" everything worked.

Naming the filename exactly like the modulename seems to confuse python...

I also named my app pygame.py and i had the same issue but when i changed it, it worked for me .

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