无法执行脚本Pyinstaller

时间:2020-10-08 14:33:43

标签: python exe pyinstaller

我使用pygame制作了一个游戏,并将其更改为可执行文件,但显示错误无法正常执行脚本rhythmtap。

错误消息:

Traceback <most recent call last>:
    File "rhythmtap.py", line 275, in <module>
        level_0()
    File "rhythmtap.py", line 176, in level_0
        pygame.mixer.music.load('./elements/sounds/r0.mp3')
pygame.error
[8508] Failed to execute script rhythmtap

我在.py中运行了这段代码,但没有任何错误。

我将.exe文件放在rhythmtap.py所在的目录中,但是它不起作用。我还尝试将相对路径更改为绝对路径。

rhythmtap.py

    while runs:
        if firsttile==True:
        screen.blit(bg, (0,0))
        button1.buttonblit()
        button2.buttonblit()
        button1.inmousecursor()
        button2.inmousecursor()
    
    if leveltile==True:
        screen.blit(selectlv, (0,0))
        preb.buttonblit()
        nextb.buttonblit()
        playb.buttonblit()
        playb.inmousecursor()
        if gopre==True:
            if level>0:
                level=level-1
            gopre=False
        if gonext==True:
            if level < 0:
                level+=1
            gonext=False
        screen.blit(tmfont.render('Rhythm  '+str(level), True, (0,0,0)), (175, 260))
        
        if (record[level])[0]=="C":
            screen.blit(tmfont.render('Cleared', True, (0,0,0)), (193, 150))
            screen.blit(tmfont1.render(str((record[level])[1]), True, (0,0,0)), (200, 210))
        if (record[level])[0]=="N":
            screen.blit(tmfont.render('Not Cleared', True, (0,0,0)), (155, 100))
    if playbool==True:
        screen.fill((255,255,255))
        screen.blit(tmfont.render('Rhythm  '+str(level), True, (0,0,0)), (175, 20))
        if level==0:
            if not tutstart:
                if califin==0:
                    screen.blit(tmfont.render('Welcome! Let\'s start.', True, (0,0,0)), (20, 70))
                    screen.blit(tmfont.render('Listen to these two sounds.',True, (0,0,0)), (20,  120))
                    screen.blit(tmfont.render('I think you need to calibrate.', True, (0,0,0)), (20, 170))
                    tapb.buttonblit()
                    tapb.inmousecursor()
                    passb.buttonblit()
                    passb.inmousecursor()
                    tutb.buttonblit()
                    tutb.inmousecursor()
                else: 
                    level_0()
            
    if calitile:
        screen.fill((255, 255, 255))
        screen.blit(tmfont.render('Calibration', True, (0,0,0)), (175, 20))
        screen.blit(tmfont.render('Tap(Space) on Fourth rhythm', True, (0,0,0)), (40, 60))
        cali()
    for x in pygame.event.get():
        if x.type==pygame.QUIT:
            pygame.quit()
            sys.exit()
        if x.type==pygame.KEYDOWN:
            
            if x.key==pygame.K_SPACE:
                if calitile:
                    pmrange=(time.time()-k)-3
                    if len(calilist)<8:
                        
                        sz=True
                    print(pmrange)
                if playbool==True:
                    clear[0]+=1
                    timedelay=time.time()-k
                    if (leveltime[level])[0]+califin<timedelay<(leveltime[level])[1]+califin:
                        print(timedelay)
                        clear[1]=True
                        clear[2]=round(timedelay-(3+califin), 5)
                        cleared(level)
                        
                        records()
        if x.type==pygame.MOUSEBUTTONDOWN:
            if firsttile==True:
                button1.clicke()
                button2.clicke()
            if leveltile==True:
                preb.clicke()
                nextb.clicke()
                playb.clicke()
            if playbool and level==0 and califin==0:
                tutb.clicke()
                tapb.clicke()
                passb.clicke()
    
    pygame.display.flip()

level_0功能

def level_0():
    global r,k
    if r==True:
        pygame.mixer.music.load('./elements/sounds/r0.mp3')

    if not pygame.mixer.music.get_busy():
        k=time.time()
        print('aweg')
        pygame.mixer.music.play()

我很困惑为什么此代码有效,

pygame.mixer.Sound('./elements/sounds/tap.wav')
pygame.mixer.Sound('./elements/sounds/kick.wav')

但这不是:

pygame.mixer.music.load('./elements/sounds/r0.mp3')

有什么解决方案可以解决这个问题吗?

0 个答案:

没有答案