0

I'm new to Python, and I'm trying to get started with Pygame.

When I run this code:

import pygame
pygame.init()

I get this error:

Traceback (most recent call last):
  File "C:\Users\Jason\PycharmProjects\Game\myapp.py", line 6, in <module>
    pygame.init()
AttributeError: 'module' object has no attribute 'init'

But when I try to see if I accidentally imported another file:

import pygame
import inspect

# Initialize the game engine
print(inspect.getfile(pygame))
pygame.init()

I get this weird error:

Traceback (most recent call last):
  File "C:\Users\Jason\PycharmProjects\Game\myapp.py", line 5, in <module>
    print(inspect.getfile(pygame))
  File "C:\Python34\lib\inspect.py", line 518, in getfile
    raise TypeError('{!r} is a built-in module'.format(object))
TypeError: <module 'pygame' (namespace)> is a built-in module

How can I import the right Pygame?

I'm using 3.4 on Windows 7 and Pygame 1.9.2a0 (for 3.2) in C:/Python34.

Thank you

  • Did you create a file or directory called "pygame" somewhere yourself? How did you install pygame? – BrenBarn Dec 06 '14 at 21:13
  • I used the default installer. I didn't create anything called pygame –  Dec 06 '14 at 21:20
  • I think the trouble is the version. I installed Python 3.2 just now, but how do I configure pygame? –  Dec 06 '14 at 21:30
  • There is a version of pygame for Python 3.4 availabe here, you could try that. Whatever version of Python you use, you'll need to install a version of Pygame for that Python version. – BrenBarn Dec 06 '14 at 21:45
  • I did install it for 3.2 and I just installed Python 3.2 –  Dec 06 '14 at 21:53

1 Answers1

0

It all has to with the version. That simple.

The original answer was here: https://stackoverflow.com/a/23484831/2486953

I had to download the 64 bit version from here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame

Thanks @BrenBarn for your help!

Community
  • 1
  • 1