带有PyInstaller的独立文件

2024-05-16 00:41:19 发布

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

我与PySimpleGUI一起开发了一个python脚本。现在我正试图将其转换为独立文件,但当我使用PyInstaller创建EXE文件时,可执行文件就是不起作用。我双击,什么也没有出现。我相信我的py文件中有错误,导致PySimpleGUI窗口无法显示。 下面是我代码的一部分:

sg.theme('DarkTeal9')
ttk_style = ''

layout =   [
        [sg.T(ttk_style)],
        [sg.Text('APP', font=("Calibri", 20))],
    
        [sg.Text('   ')],

        [sg.Text('Fichero ARC Laurea:'), sg.Input(), sg.FileBrowse()],
        [sg.Text('Fichero Oferta Laurea:'), sg.Input(), sg.FileBrowse()],
        [sg.Text('Fichero Nóminas:'), sg.Input(), sg.FileBrowse()],
        [sg.Button('Procesar',bind_return_key=True,use_ttk_buttons=True)],
        [sg.Text('Ventana de progreso:')],
        [sg.Output(size=(75,25),key='inputbox')],
        [sg.Text('   ')]]
                    
iconpath=\somepathtoimage

window = sg.Window('myapp',icon=iconpath, ttk_theme=ttk_style).Layout(layout)



while True: 
    event, values = window.Read()
    if event in (None, 'Exit'):
        break
        
    if event == 'Procesar':
        arc_ruta=values[0]
        propuestas_ruta=values[1]
        nominas_ruta=values[2]

        generar_propuestas(arc_ruta, propuestas_ruta, nominas_ruta) #calling the function

    elif event == 'Process':
        for filename in glob.glob(os.path.join(path, '*.xlsx')):
            with open(filename,'rb') as f:
                pdf = f.read()
            
    
window.close()




function()

Tags: 文件texteventtrueinputstylesgwindow
1条回答
网友
1楼 · 发布于 2024-05-16 00:41:19

我认为您丢失了这些文件,如果您从CMD打开exe,在exe所在的位置打开CMD并“/yourapp.exe”,您可以看到错误

此外,您还必须启用调试模式,您可以在pyinstaller的.spec文件中进行这些更改

这是我的样本:

import sys
import os

path = os.path.abspath(".")

block_cipher = None

a = Analysis(['F:\\path\\to\\your\\main.py'],
             pathex=['F:\\path\\to\\project'],
             binaries=[],
             datas=[('F:\\path\\to\\folder\\dataneeded','.'),
                    ('F:\\path\\to\\folder\\dataneeded\\*.png','.\\dataneeded'),
                    ('F:\\path\\to\\folder\\dataneeded\\*.ico','.\\dataneeded')
                    ],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False
             )
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
          [],
          name='Appname',
          debug=True,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          upx_exclude=[],
          runtime_tmpdir=None,
          console=True )
coll = COLLECT(exe, Tree('F:\\path\\to\\project'),
               a.binaries,
           a.zipfiles,
           a.datas,
           *[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
               strip=False,
               upx=True,   
               name='Appname')


您必须在数据中添加所需的所有文件,如上图所示 例如,您有一个包含图像的文件夹 首先设置文件夹,然后设置必须放入文件夹的文件类型

相关问题 更多 >