【问题标题】:Standalone file with PyInstaller带有 PyInstaller 的独立文件
【发布时间】:2021-06-10 08:00:43
【问题描述】:

我与 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()

【问题讨论】:

  • 按照@Idontknowsohelpme 的建议,尝试从终端启动可执行文件以查看任何错误消息。请将错误消息与您的问题一起发布。知道错误可以更容易(帮助您)解决问题。

标签: python python-3.x pyinstaller pysimplegui


【解决方案1】:

我认为你丢失了文件,如果你从 CMD 打开你的 exe,你可以看到错误,打开你的 exe 所在的 CMD 和“./yourapp.exe”

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

这是我的示例:

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')


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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-18
    • 1970-01-01
    • 2019-12-19
    • 2021-01-16
    • 1970-01-01
    • 2018-05-22
    相关资源
    最近更新 更多