Pygame.init() not working [duplicate]

爱⌒轻易说出口 提交于 2019-12-30 14:29:41

问题


I downloaded pygame successfully but now when I do:

import pygame
pygame.init()
size =  [400, 400]

pygame.display.set_mode(size)

it gives errors:

Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module> pygame.init AttributeError:
'module' object has no attribute 'init'

And nothing is working for me. Please help me use init and display.

I am using

  • python 3.4.1 and
  • pygame 1.9.2 on
  • Windows 7 32bit and
  • I installed pygame on

    c://python34/include/
    

回答1:


You probably had named your file pygame.py
when you type:

import pygame

python won't import pygame module you want, instead it will try import local module pygame - your file. and your file hasn't method init. try change file name from pygame.py to mypygame.py.




回答2:


I had the same problem, but then I reinstalled everything and realized that I had a different version of pygame than I needed for python

I realized also that I shouldn't use the .zip archive to install. I looked in there and saw that there's an installer for it if you're on any major OS. For example, for Macintosh, there's .dmg files. For Windows, there's .msi, etc.




回答3:


You probably installed your pygame library in the include/ folder, but somehow didn't have the correct files inside it. This may of happened because of some downloading issues or the website you were downloading from. Hope this helps! You want to type downloading pygame from pygame.org instead of some other places on the web because of possible errors or changes in code.



来源:https://stackoverflow.com/questions/25330168/pygame-init-not-working

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