我有以下 pyinstaller 规范文件
我有一个翻译文件在./translate/nl_NL.qm
从 datas=[ ('translate/nl_NL.qm', 'translate' )] 行开始,我希望该文件被复制到 ./dist/translate/nl_NL.qm。
我做错了什么?
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['inifileedit.py'],
pathex=['/home/rob/socktest/qt5projects/inifileedit'],
binaries=[],
datas=[ ('translate/nl_NL.qm', 'translate' )],
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='inifileedit',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=False )
Eric Mathieu 解决了我的问题
它发现 pyinstaller 将数据解压到的位置与我想象的不同
此代码可在解释器和 pyinstaller 中运行
# get path to where pyinstaller will unpack ./translate
# if not packed by pyinstaller returns location of .py file
bundle_dir = getattr(sys, '_MEIPASS', path.abspath(path.dirname(__file__)))
if (Lang == "Eng"):
_tr = "translate/en_US.qm"
if (Lang == "Dut"):
_tr = "translate/nl_NL.qm"
self.translator.load(path.join(bundle_dir, _tr))