问题
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