-1

This is my error:

enter image description here

However there is a file at 'C:/Python34/Python34/build/exe.win32-3.4/library.zip/pygame/freesansbold.ttf' Look:

enter image description here

When I check for the file by swiping in from right on my computer and typing address it also says it doesn't exist. Why is this as it clearly does!?!?!?

I know other people have asked SIMILAR questions but none of them answer my question. EXTRA INFORMATION: The program works in IDLE fine, but not when compiled I'm using Python 3.4 32-Bit and Pygame 32-Bit I'm on Windows 8.1 64-Bit I'm trying to make flappy cube :P

If you need any extra info, just ask! `

import pygame
import random
import time
pygame.init()

display_width = 1450
display_height = 720
cube_width = 5

white = (255,255,255)
red = (255,0,0)
green = (0,255,0)
blue = (0,0,255)
black = (0,0,0)
lel = (205,205,255)

cube_colour = white

gameDisplay = pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption('Flappy Cube')
clock = pygame.time.Clock()
dodged = 0


################################################################################
def things_dodged(count):
    font = pygame.font.Font('freesansbold.ttf',50)
    text = font.render("Dodged: "+str(count),True,blue)
    gameDisplay.blit(text,(0,0))
    pygame.display.update()

def cube_draw(cubex, cubey, cube_width, cube_height, colour):
    pygame.draw.rect(gameDisplay, colour, [cubex, cubey, cube_width, cube_height])
    pygame.display.update()

def pipe_draw(pipex,pipey,pipe_width,pipe_height,colour):
    pygame.draw.rect(gameDisplay, colour,[pipex, pipey, pipe_width, pipe_height])

def msg_objects(msg, font):
    msgSurf = font.render(msg, True, blue)
    return msgSurf, msgSurf.get_rect()

def message_display(msg):
    font_size = pygame.font.Font('freesansbold.ttf',72)
    msgSurf, msgRect = msg_objects(msg, font_size)
    msgRect.center = ((display_width /2), (display_height / 2))
    gameDisplay.blit(msgSurf, msgRect)
    pygame.display.update()
    time.sleep(1)
    game_loop()

def crash(msg):
    message_display(msg)
################################################################################    
def game_loop():

    pipex = 500
    pipey = display_height
    pipe_width = 10
    pipe_height10 = random.randint(30,500)

    while pipe_height10 % 30 != 0:
        pipe_height10 = random.randint(30,500) 
    pipe_height = pipe_height10 * -1
    #
    up_pipex = 500
    up_pipey = 0
    up_pipe_width = 10
    up_pipe_height = display_height - (pipe_height * -1) - 80
    ###
    pipex1 = 1000
    pipey1 = display_height
    pipe_width1 = 10
    pipe_height11 = random.randint(30,500)

    while pipe_height11 % 30 != 0:
        pipe_height11 = random.randint(30,500) 
    pipe_height1 = pipe_height11 * -1
    #
    up_pipex1 = 1000
    up_pipey1 = 0
    up_pipe_width1 = 10
    up_pipe_height1 = display_height - (pipe_height1 * -1) - 90
    ###
    cubex = 20
    cubey = (display_height / 2)
    cube_width = 40
    cube_height = 40 

    gameExit = False
    y_change = 0
    dodged = 0

    if dodged==0:
        pipe_speed = -2 

    while not gameExit:
        if dodged>0:
            pipe_speed = -2.5
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE:
                    y_change = -3
                elif event.key == pygame.K_p:
                    time.sleep(4)

            else:
                y_change = 2

        cubey += y_change

        gameDisplay.fill(green)

        pipe_draw(pipex, pipey, pipe_width, pipe_height, lel)
        pipe_draw(pipex1, pipey1, pipe_width1, pipe_height1, lel)

        pipe_draw(up_pipex, up_pipey, up_pipe_width, up_pipe_height, lel)
        pipe_draw(up_pipex1, up_pipey1, up_pipe_width1, up_pipe_height1, lel)

        cube_draw(cubex, cubey, cube_width, cube_height, red)
        pipex += pipe_speed
        pipex1 += pipe_speed
        up_pipex += pipe_speed
        up_pipex1 += pipe_speed
        things_dodged(dodged)


        ###
        if cubey < 0 or cubey > display_height - cube_height:
            crash('You Hit The Side!')


        if pipex < cubex + cube_width:
            if display_height + pipe_height < cubey + cube_height or up_pipe_height > cubey:
                crash('You Hit A Pipe!')

            pipe_height10 = random.randint(30,550)
            while pipe_height10 % 30 != 0:
                pipe_height10 = random.randint(30,550) 
            pipe_height = pipe_height10 * -1
            pipex += 1000
            dodged += 1

            up_pipe_height = display_height - (pipe_height * -1) - 120
            up_pipex += 1000

        if pipex1 < cubex + cube_width:
            if display_height + pipe_height1 < cubey + cube_height or up_pipe_height1 > cubey:
                crash('You Hit A Pipe!')

            pipe_height11 = random.randint(30,550)
            while pipe_height11 % 30 != 0:
                pipe_height11 = random.randint(30,550) 
            pipe_height1 = pipe_height11 * -1
            pipex1 += 1000

            up_pipe_height1 = display_height - (pipe_height1 * -1) - 120
            up_pipex1 += 1000

            dodged += 1

        pygame.display.update()
        clock.tick(10000)

##############################################################################
game_loop()
`

EDIT:
A big thanks to @Martijn Pieters for answering this question

Funk Pigeon
  • 168
  • 2
  • 12
  • 2
    An error message is *text*, please copy and paste that text into your question rather than use a screenshot. – Martijn Pieters Apr 05 '15 at 13:11
  • Martijn Pieters that's not very helpful – Funk Pigeon Apr 05 '15 at 14:27
  • 1
    What isn't helpful? My comment or copying the error message? Text can be copied from your post here again, to help people helping you search for additional information. It'll also help others with the same problem locate your question as they can search for the error message. – Martijn Pieters Apr 05 '15 at 15:00
  • related: [python: can executable zip files include data files?](http://stackoverflow.com/q/5355694/4279) – jfs Oct 18 '15 at 17:55

1 Answers1

1

Your file is contained in a ZIP archive. Your Windows Explorer may automatically unzip such files for you, but Python cannot.

Extract the file and put it somewhere else, or open the zipfile each time from your program, extract the file to a temporary location each time and have PyGame load the font from that temporary location.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • so basically I can copy&paste the freesansbold.ttf to 'Downloads' for example or to C:/Python34/Python34 and then instead off 'freesansbold.ttf' in things_dodged() and display_message() i can have 'C:/Python34/Python34/freesansbold.ttf'. Am I right? – Funk Pigeon Apr 05 '15 at 14:01
  • Correct; that way you don't have to use Python to extract it from `library.zip`. – Martijn Pieters Apr 05 '15 at 14:05
  • It works. Thank you so much! Just wondering: if someone else downloaded my .exe and tried to run it would it work as the font address is 'C:/Python34/Python34/freesansbold.ttf' I think this wouldnt work as the font file may not be at that address on their PC. If this is a problem, could you tell me how to fix it plz? – Funk Pigeon Apr 05 '15 at 14:38
  • @FunkPigeon: you'll have to extract the file from `library.zip` every time you run your program. I'd use the `tempfile` module to create a temporary directory, use the `zipfile` module to extract just that font file from the `library.zip` archive to the directory, then use that new path to load the font file each time you run your executable. – Martijn Pieters Apr 05 '15 at 14:58
  • @FunkPigeon: if you built this with `py2exe` or similar tool then you need to read the documentation to see if there is a way to register that certain files should *not* be zipped up, so that you distribute the font together with the executable. Then you wouldn't have to extract it each time. – Martijn Pieters Apr 05 '15 at 14:59