Pygame error: 'pygame' has no attribute 'init'
I just downloaded Pygame but is running into an error: AttributeError: module 'pygame' has no attribute 'init'. I was looking around on stackoverflow and someone fixed the error by renaming the files (which I don't know how to do). The directory is the following
Python -> Lib -> site-packages ->pygame
The confusing part for me is inside the pygame folder
pygame > Include, Lib
Include > pygame > (many hh files)
Lib > SitePackages > pygame > init (I know that it has the attribute init)
Since there is '3' pygame folder, is this causing the error for my program?
import pygame, sys
pygame.init()
DISPLAYSURF = pygame.display.set_mode((400, 300))
pygame.display.set_caption('Hello World!')
while True: # main game loop
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
Just rename your file from pygame.py
to myTestGame.py
for example because you're importing the same file when you use import pygame
It looks as though you have "downloaded" a source distribution of pygame, and then copied the content into site-packages
. that works fine for most pure-python libraries, but not for ones with c-extensions, like pygame. You are probably best served by using an installer, as pygame is a bit tedious to build from source.
Visit http://www.pygame.org/download.shtml and choose an installer for your OS. note that the first two links are source downloads, and not what you need.
The most current, best way to install pygame is available at: https://www.pygame.org/wiki/GettingStarted
Currently, for windows, it says to install it like this in a cmd window:
py -m pip install pygame --user