我有一个tkinter程序,包括一个.png图像。我已经使用pyinstaller和--onefile选项编译了它,所以我必须在临时位置访问图像。这是我正在使用的代码:
def resource_path(relative_path):
try:
base_path = sys._MEIPASS
except Exception as e:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
title = PhotoImage(file=resource_path("xgol.png"))
这是我的.spec文件:
# -*- mode: python -*-
block_cipher = None
a = Analysis(['XGols.py'],
pathex=['C:\\Users\\Sam\\OneDrive\\Computing\\Python Projects\\FootballPredict'],
binaries=[],
datas=[('Ball.ico', 'Ball.ico'), ('xgol.png', 'xgol.png')],
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,
[],
name='XGols',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
runtime_tmpdir=None,
console=True , icon='Ball.ico')
要编译我使用的程序:
pyinstaller --onefile XGols.spec
This is the error that I get when I run the executable
_tkinter.TclError: couldn't open "C:\Users\Sam\AppData\Local\Temp\_MEI61842\xgol.png": permission denied
我试过当管理员。你知道吗
在
.spec
文件中,其他数据文件应如下所示:从the documentation:
相关问题 更多 >
编程相关推荐