如何在python中将音频资源和py文件打包成exe?

如何在python中将本地音频资源和py文件打包成exe,需要详细过程

pyinstaller
需要的资源文件全部丢进去即可
https://www.cnblogs.com/helloworldcc/p/9427519.html

import base64

def ToBase64(file, txt):
    with open(file, 'rb') as fileObj:
        image_data = fileObj.read()
        base64_data = base64.b64encode(image_data)
        fout = open(txt, 'w')
        fout.write(base64_data.decode())
        fout.close()


def ToFile(txt, file):
    with open(txt, 'r') as fileObj:
        base64_data = fileObj.read()
        ori_image_data = base64.b64decode(base64_data)
        fout = open(file, 'wb')
        fout.write(ori_image_data)
        fout.close()

ToBase64('data/1.mp3', 'audio.py')
ToFile('audio.py','2.mp3')

假设生成的audio.py

asdingsdf

修改成
···
s = "asdingsdf"
···

读取
···
import base64
import audio
def ToFile(txt, file):
base64_data = audio.s
ori_image_data = base64.b64decode(base64_data)
fout = open(file, 'wb')
fout.write(ori_image_data)
fout.close()
···

你的音频文件不是太大的时候,可以将对应的音频文件内容设置为一变量,
如果文件 比较大,还是建议随exe文件一起打包发布