我试图使用pyinstaller将我的python文件转换为exe。我该如何编辑我的spec文件?

时间:2018-03-27 07:42:14

标签: python python-3.6 pyinstaller py2exe

这是我找到的spec文件演示。问题我在这方面非常业余。我不知道我需要做些什么改变。我有两个python脚本,其中一个将是我的可执行文件和其他我用作模块,我也有一个json文件。 这是我找到的代码

    # -*- mode: python -*-
a = Analysis(['..\\..\\bin\\kano-burner'],
             pathex=['C:\\Kano\\kano-burners'],
             hiddenimports=[],
             hookspath=None,
             runtime_hooks=None)


import os
import glob

def extra_datas(path):
    def recursive_glob(path, files):
        for file_path in glob.glob(path):
            if os.path.isfile(file_path):
                files.append(os.path.join(os.getcwd(), file_path))
            recursive_glob('{}/*'.format(file_path), files)

    files = []
    extra_datas = []

    if os.path.isfile(path):
        files.append(os.path.join(os.getcwd(), path))
    else:
        recursive_glob('{}/*'.format(path), files)

    for f in files:
        extra_datas.append((f.split('kano-burners')[1][1:], f, 'DATA'))
    return extra_datas

a.datas += extra_datas(os.path.join(os.getcwd(), '..', '..', 'res'))
a.datas += extra_datas(os.path.join(os.getcwd(), '..', '..', 'win'))
a.datas += extra_datas(os.path.join(os.getcwd(), '..', '..', 'DISCLAIMER'))


pyz = PYZ(a.pure)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          name='Kano Burner.exe',
          debug=False,
          strip=None,
          upx=True,
          console=False , icon='..\\..\\res\\icon\\burner_icon.ico')

1 个答案:

答案 0 :(得分:1)

对于您的简单情况,您应该直接使用pyinstaller命令行。

pyinstaller --onefile main.py childModule.py

可以使用

添加任何其他文件
--add-data

选项。

相关问题