执行pyinstaller可执行文件时出错

时间:2019-05-16 05:45:06

标签: python tkinter pyinstaller

我在--onedir模式下使用以下规范文件创建了一个exe文件。已成功在dist文件夹下创建该文件夹。我可以在onedir文件夹ROY中看到要求。

# -*- mode: python -*-

block_cipher = None


a = Analysis(['C:\\Users\\****\\AppData\\Local\\Programs\\Python\\Python37-32\\final.py'],
             pathex=['C:\\Users\\****'],
             binaries=[('bg.png', 'bg.png')],
             datas=[('C:\\Users\\****\\AppData\\Local\\Programs\\Python\\Python37-32\\Lib\\site-packages', 'ttkthemes')],
             hiddenimports=['ttkthemes'],
             hookspath=[],
             runtime_hooks=[],
             excludes=['scipy'],
             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,
          [],
          exclude_binaries=True,
          name='final',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='final')

执行exe文件后出现以下错误:

Traceback (most recent call last):   
File "final.py", line 1043, in <module>   
File "final.py", line 40, in __init__   
File "site-packages\ttkthemes\themed_tk.py", line 43, in __init__   
File "site-packages\ttkthemes\_widget.py", line 72, in __init__   
File "site-packages\ttkthemes\_widget.py", line 78, in _load_themes
_tkinter.TclError: couldn't read file "themes/pkgIndex.tcl": no such file or directory

pkgIndex.tcl确实存在于themes文件夹下。我应该在ttkthems文件中特别对待spec吗?我应该添加任何挂钩吗?

请帮助我解决这个问题!

1 个答案:

答案 0 :(得分:1)

仅导入site-packges文件夹,而不是导入整个ttkthemes文件夹。我已经更新了datasbinaries。使用images将在主images文件夹(--onedir)下创建一个名为final的文件夹,您也可以提供其他名称。根据您的代码,它将在bg.png文件夹内创建一个名为final的文件夹。

语法为binaries = [(file_name,destination_folder), (file_name,destination_folder)],您可以根据需要添加任意数量的文件。

# -*- mode: python -*-

block_cipher = None


a = Analysis(['C:\\Users\\****\\AppData\\Local\\Programs\\Python\\Python37-32\\final.py'],
             pathex=['C:\\Users\\****'],
             binaries=[('bg.png', 'images')],
             datas=[('C:\\Users\\****\\AppData\\Local\\Programs\\Python\\Python37-32\\Lib\\site-packages\\ttkthemes', 'ttkthemes')],
             hiddenimports=['ttkthemes'],
             hookspath=[],
             runtime_hooks=[],
             excludes=['scipy'],
             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,
          [],
          exclude_binaries=True,
          name='final',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='final')