我在--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
吗?我应该添加任何挂钩吗?
请帮助我解决这个问题!
答案 0 :(得分:1)
仅导入site-packges
文件夹,而不是导入整个ttkthemes
文件夹。我已经更新了datas
和binaries
。使用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')