0

this is my first post here. I saw plenty of similar issues but mine is kinda specific. To get into subject i need to make single file executable with python which i did with py2exe and Iexpress. Everything worked perfectly untill i included pictures (.png) yesterday. After compiling with py2exe everything worked so im quite sure pygame is capable of opening .png but when i compressed with Iexpress which is supposed only to unpack them in temp folder i get:

"Traceback (most recent call last): File "Game.py", line 23, in pygame.error: File is not a Windows BMP file"

So i get 2 exactly same folders, first pre-iexpress that works and second temp folder which doesn't. I used Python 3.4 and pygame‑1.9.2a0‑cp34 This is my code

__author__ = 'Xpd'
        back = "bg.png"
        sh = "ship.png"
        ali = "alien.png"
        import pygame
        import random
        import sys
        pygame.init()
        white = (255,255,255)
        black = (0,0,0)
        red = (255,0,0)
        green =(0,255,0)
        blue = (0,0,255)
        display_width = 800
        display_height = 600



        clock = pygame.time.Clock()

        gameDisplay = pygame.display.set_mode((display_width,display_height), 0, 0)
        pygame.display.set_caption('Invaders')
        background = pygame.image.load(back)
        ship = pygame.image.load(sh)
        alien = pygame.image.load(ali)
        def Intro():
            Intro = True
            while Intro == True:
                gameDisplay.fill(green)
                pygame.display.update()
                for event in pygame.event.get():
                    if event.type == pygame.KEYDOWN:
                        if event.key == pygame.K_UP:
                            Intro = False
                    if event.type == pygame.QUIT:
                            pygame.quit()
                            sys.exit()
        def text_to_button(msg, color, buttonx, buttony, buttonwidth, buttonheight, size = "small"):
            textSurf, textRect = text_objects(msg,color,size)
            textRect.center = ((buttonx+(buttonwidth/2)), buttony+(buttonheight/2))
            gameDisplay.blit(textSurf, textRect)

            return textSurface, textSurface.get_rect()



        def text(msg,color, y_displace=0, size = "small"):
            textSurf, textRect = text_objects(msg,color, size)
            textRect.center = (display_width / 2), (display_height / 2)+y_displace
            gameDisplay.blit(textSurf, textRect)

        def GameLoop():
            gameExit = False
            gameOver = False
            prime_x = display_width/2
            block = 3
            fps=300
            alien_x = random.randrange(50,300)
            alien_y = random.randrange(50,300)
            alien_health = 1
            ship_health = 3
            ship_damage = 1


            bulletspeed = 0
            bullet_y = 550
            bullet_x = -50
            bullet_size = 5
            movement = 0


            while gameOver == True:
                for event in pygame.event.get():
                    if event.type == pygame.KEYDOWN:
                        if event.key == pygame.K_q:
                            gameExit = True
                        if event.key == pygame.K_c:
                            GameLoop()


            while not gameExit:
                if prime_x <= 0:
                            prime_x = 0
                if prime_x >= 790:
                            prime_x = 790
                for event in pygame.event.get():
                    print(event)
                    if event.type == pygame.QUIT:
                         gameExit = True
                         gameQuit = True
                    if event.type == pygame.KEYDOWN:
                        if event.key == pygame.K_LEFT:
                            movement = -block
                        if event.key == pygame.K_RIGHT:
                            movement = block
                        if event.key == pygame.K_SPACE:
                            if bullet_y < 0:
                                    bullet_y = 550
                            if bullet_y == 550:
                                bulletspeed = -bullet_size
                                bullet_x = prime_x
                                if bullet_y < 0:
                                    bullet_y = 550




                    if event.type == pygame.KEYUP:
                        if event.key == pygame.K_RIGHT or pygame.K_LEFT:
                            movement = 0

                if alien_x < bullet_x < alien_x + 50 or alien_x < bullet_size + bullet_x < alien_x + 50:
                        if alien_y < bullet_y < alien_y + 50 or alien_y < bullet_size + bullet_y < alien_y + 50:
                            alien_health -= ship_damage
                            bulletspeed = 0
                            bullet_y = 550
                            bullet_x = -50
                            if alien_health <= 0:
                                alien_x = random.randrange(50,300)
                                alien_y = random.randrange(50,300)
                                alien_health = 1


                prime_x += movement
                bullet_y += bulletspeed
                pygame.draw.rect(gameDisplay, green,[alien_x,alien_y,50 ,50 ] )
                gameDisplay.blit(background, (0,0))
                gameDisplay.blit(alien, (alien_x,alien_y))

                gameDisplay.blit(ship, (prime_x-22,545))

                pygame.draw.rect(gameDisplay, red, [bullet_x, bullet_y,bullet_size, bullet_size])
                pygame.display.update()
                clock.tick(fps)


        Intro()
        GameLoop()
        pygame.quit()
        sys.exit()

Inside Iexpress i placed: alien.png, bg.png, Game.exe, SDL.dll, SDL_IM~1.dll, SDL_MI~1, SDL_ttf.dll, ship.png, smpeg.dll

Apologies if i did something wrong here, this is my first project.

EDIT: pygame.image.get_extended() returns 1, using Windows 8.1 tested Iexpress 32bit and 64bit still not working.

1 Answer 1

1

I cannot comment so here's an 'Answer'...
You python looks good. I'd assume it's IExpress which is great, but can be a little tricky to troubleshoot. Here are things I'd try:

  1. The easy one - check to make sure the file isn't empty and was extracted properly (filesize, name, and other properties). The file isn't opened by another process (IExpress isn't paused extracting, etc).
  2. Check the log file of IExpress when it compresses
  3. Check if you have UseLongFileName=1 in your IExpress config file (*.sed)
  4. Check to make sure everything is extracting propery
    change your IExpress config file to have the following settings ShowInstallProgramWindow=3 HideExtractAnimation=0 AppLaunched=cmd /C "echo begin&&pause&&echo end" NOTE: Make sure you have ShowInstallProgramWindow=3 so you want have a hidden process waiting for user input - locking resources.
  5. A variant of #4, change the installation command to copy the temp folder elsewhere before exiting. AppLaunched=cmd /C "copy * C:\some\folder\&&pause"
  6. The boring one. Create a pythong script to read both BMP files and check byte for byte if there's a difference, something like the following...
    import os org = open('original.bmp','rb') new = open('new.bmp','rb') size_compared = 0 comp_size = 1 MAX_SIZE = max(os.path.getsize(i) for i in ('original.bmp','new.bmp')) print 'comparing bytes...' while True: a = org.read[comp_size] b = new.read[comp_size] size_compared += comp_size if a!=b: print 'bytes don't match!' print '{} != {}'.format(a,b) print 'at byte {}'.format(size_compared) break if a=='' and b=='': break # files are empty if MAX_SIZE < size_compared: break # just in case... shouldn't happen... org.close() new.close() print 'done comparing... anything found?'

If you have any questions please ask - enjoy.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.