Python 3.4 FileNotFoundError:[Ernno 2]没有这样的文件或目录,但文件是

2024-06-26 18:00:53 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的错误:

enter image description here

但是在'C:/Python34/Python34/build有一个文件/exe.win32-3.4条/library.zip/pygame/freesansbold.ttf' 看:

enter image description here

当我从我的电脑上从右边刷入并输入地址来检查文件时,它也会说它不存在。为什么会这样呢!?!?!?在

我知道其他人也问过类似的问题,但没有人回答我的问题。 额外信息: 程序可以在空闲状态下正常工作,但编译时不行 我使用的是python3.4 32位和Pygame 32位 我使用的是64位Windows 8.1 我在试着做松饼方块:P

如果你需要更多的信息,尽管问! `在

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

编辑
非常感谢@Martijn Pieters回答了这个问题


Tags: ifdisplayrandomwidthpygameheightdrawup
1条回答
网友
1楼 · 发布于 2024-06-26 18:00:53

您的文件包含在ZIP存档中。您的Windows资源管理器可能会自动为您解压缩这些文件,但Python不能。在

提取文件并将其放在其他地方,或者每次从程序中打开zipfile,每次都将文件提取到临时位置,然后让PyGame从该临时位置加载字体。在

相关问题 更多 >