ImportError: no module named pygame ? I have Pygame!

This is the place for queries that don't fit in any of the other categories.

ImportError: no module named pygame ? I have Pygame!

Postby Hissing Cockroach » Wed Oct 30, 2013 7:23 pm

I can import pygame through the command line, and through all my other
prorams, but it brings up an error in my crosshairs program:

Code: Select all
Traceback (most recent call last):
  File "C:\Users\Family\Desktop\pys\Crosshairs(2).py", line 1, in <module>
    import pygame
ImportError: No module named 'pygame'


I have no idea what the heck it's talking about, but
I'm thinking this could be windows vista being very glitchy,
but I'm not too sure. Does anyone know what the problem is?
If you need it, here is the code:

Code: Select all
import pygame
import math
import sys

WHITE    = (255, 255, 255)
BLACK    = (  0,   0,   0)
RED = (255, 0, 0)

BGCOLOR = WHITE

WINDOWWIDTH = 640
WINDOWHEIGHT = 480



       
class Control(object):

    def __init__(self):
        self.bullet_holes = []
        self.screen = pg.display.set_mode((WINDOWWIDTH,WINDOWHEIGHT))
        self.done = False
        self.clock = pg.time.Clock()

    def update(self):
        vis = False
        pygame.mouse.get_visible(vis)
        self.mousex,self.mousey = pg.mouse.get_pos()
        self.screen.fill(BGCOLOR)
        pygame.draw.circle(self.screen, RED, (320,240),50,10)
        pygame.draw.circle(self.screen, WHITE, (320,240),40,10)
        pygame.draw.circle(self.screen, RED, (320,240),30,10)
        pygame.draw.circle(self.screen, WHITE, (320,240),20,10)
        pygame.draw.circle(self.screen, RED, (320,240),10,10)
        pygame.draw.line(self.screen, BLACK, (self.mousex - 2000, self.mousey), (self.mousex + 2000, self.mousey))
        pygame.draw.line(self.screen, BLACK, (self.mousex, self.mousey - 2000), (self.mousex, self.mousey + 2000))
        for bullet_pos in self.bullet_holes:
            pygame.draw.circle(self.screen,BLACK,bullet_pos,5)
           
    def event_loop(self):
        for event in pg.event.get():
            if event.type ==  pg.QUIT or (event.type == pg.KEYUP and event.key == pg.K_ESCAPE):
                self.done = True
            elif event.type == pg.MOUSEBUTTONDOWN and event.button == 1:
                self.bullet_holes.append(event.pos)
                pygame.image.save(self.screen,'Highscores.png')

    def main_loop(self):
        while not self.done:
            self.update()
            self.event_loop()
            pygame.display.flip()
            self.clock.tick(60)

   

if __name__ == '__main__':
    game = Control()
    game.main_loop()
    pygame.quit()
    sys.exit()
User avatar
Hissing Cockroach
 
Posts: 108
Joined: Sat Sep 14, 2013 2:35 pm
Location: Earth

Re: ImportError: no module named pygame ? I have Pygame!

Postby Mekire » Wed Oct 30, 2013 11:39 pm

Hissing Cockroach wrote:I'm thinking this could be windows vista being very glitchy
This is probably not the case. Don't cry glitch every time something doesn't work for you. Nothing will frustrate people more.

Could you confirm a few things:
If you put another program that uses pygame in the exact same directory, does it run? What version of python are you using? Is it possible that you have both python 3 and python 2 on your machine (but only have pygame for one of them)? How are you running the program (command line; double click; IDLE/IDE)? Did you ever set up your python path (which includes adding to the environmental variables in windows)?

Also, this isn't the issue here, but you should note that you are combining my code where I use
Code: Select all
import pygame as pg
with code that is trying to use pygame imported normally. Assuming pygame imports correctly you will immediately get an error telling you that pg was never defined.

-Mek
User avatar
Mekire
 
Posts: 1125
Joined: Thu Feb 07, 2013 11:33 pm
Location: Asakusa, Japan

Re: ImportError: no module named pygame ? I have Pygame!

Postby Hissing Cockroach » Thu Oct 31, 2013 9:47 pm

If you put another program that uses pygame in the exact same directory, does it run?______Yes

What version of python are you using?______2.7

Is it possible that you have both python 3 and python 2 on your machine (but only have pygame for one of them)? ______Yes, but I have not yet used the one without pygame

How are you running the program (command line; double click; IDLE/IDE)?______IDLE

Did you ever set up your python path (which includes adding to the environmental variables in windows)?______Yes

Mekire wrote:Also, this isn't the issue here, but you should note that you are combining my code where I use
Code: Select all
import pygame as pg
with code that is trying to use pygame imported normally. Assuming pygame imports correctly you will immediately get an error telling you that pg was never defined.


Am I Really? If what you mean is I put "pg" in here somewhere I don't see it.
User avatar
Hissing Cockroach
 
Posts: 108
Joined: Sat Sep 14, 2013 2:35 pm
Location: Earth

Re: ImportError: no module named pygame ? I have Pygame!

Postby dboxall123 » Thu Oct 31, 2013 10:08 pm

Am I Really? If what you mean is I put "pg" in here somewhere I don't see it.

Code: Select all
def __init__(self):
        self.bullet_holes = []
        self.screen = pg.display.set_mode((WINDOWWIDTH,WINDOWHEIGHT))
        self.done = False
        self.clock = pg.time.Clock()
dboxall123
 
Posts: 121
Joined: Fri Jul 12, 2013 5:28 pm

Re: ImportError: no module named pygame ? I have Pygame!

Postby Hissing Cockroach » Fri Nov 01, 2013 12:59 am

oh, sorry. I've been playing around with this program alot, and
unfortunately I left it still in progress.
User avatar
Hissing Cockroach
 
Posts: 108
Joined: Sat Sep 14, 2013 2:35 pm
Location: Earth

Re: ImportError: no module named pygame ? I have Pygame!

Postby Hissing Cockroach » Sun Nov 03, 2013 4:21 am

Alright, I found the problem. I have no idea why, but this program somehow
transferred to 3.3.2, which didn't have Pygame. I deleted it and now I can't even
edit my programs, so I have another problem. Does anyone know what I should do?
User avatar
Hissing Cockroach
 
Posts: 108
Joined: Sat Sep 14, 2013 2:35 pm
Location: Earth


Return to General Coding Help

Who is online

Users browsing this forum: Mekire and 2 guests