0

I have successfully used pygame in the past, but now it won't work. my source is

import pygame, sys
from pygame.locals import *

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()

using this in the shell works fine and creates a pygame window, but it will not work when making a module. it says pygame is not a package.

2
  • You probably have more than one version of Python on your system, and pygame is only installed on one of them. Are you double-clicking your .py file to run it when you get the error? Commented Dec 20, 2013 at 22:25
  • yes, i double click it. my HDD has two python folders. Pythonx and Python 33 Commented Dec 20, 2013 at 22:33

1 Answer 1

1

You have two different versions of Python installed (Python(x,y) and the python.org version), and pygame is only installed on one of them. When you run the interpreter through IDLE or the command line for the version that has pygame associated with you, you can import pygame and use it just fine. However, in Windows Explorer, .py files are associated with the other version of Python, that does not have pygame installed, so when you try to run a file by double-clicking on it the wrong Python interpreter starts, and it can't import pygame because it's not installed for that version.

To fix this, all you need to do is re-associate .py files with the correct version of Python. Right-click on a .py file, select Properties, and in the dialog box that comes up find where it says something like "Opens with:" and click the Change button. Browse to C:\Python33 and select python.exe, and you should be all set. Make sure the option "Always use the selected program to open this kind of file" is set, then click OK.

I'm on XP right now, so the process might be slightly different depending on which version of Windows you're running, but it should be fairly similar.

Sign up to request clarification or add additional context in comments.

6 Comments

that didnt do anything. im still getting the same error. how did i get the two versions of python though?
More simply, if you have no clue how to manage two Python installations at a time, and don't have a good reason why you need two of them, I'd suggest just deleting the other one. If you're only running it/installing stuff into it/etc. by accident, it's not helping…
@kookman98: You got the two versions by running two installers, one from the Python(x,y) project and one from somewhere else, probably Python.org.
@kookman98 try following my directions again, except pick the python.exe in your C:\Pythonx directory instead and see if that works...
i also checked the "include" folder in python33 and it has pygame in it
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.