pyinstaller - pyinstaller 未将数据文件复制到 ./dist 目录
问题描述
我有以下 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))
推荐阅读
- java - 从 xml 的其余部分中删除 xml 中的回车和拆分 xml 版本
- android - 不在 Google Play 商店上的 Android 应用程序的 Facebook 社交登录
- jmeter - 在 Jmeter 结果树和报告中看不到所有结果
- reactjs - 将 setState 变量作为参数传递时,如何确保它的值未定义?
- uppy - uppy.io 用于发送 base64 编码数据而不是指定文件输入
- python - 如何使用 apply() 方法在 pandas 列中应用 Geopy?
- c# - 访问模型中的属性 - C#
- spring-webflux - ServerResponse 在执行 Mono 之前返回
- react-native - 未触发 apk 上的通知
- python - 如何使用我的 config.ini 文件而不是硬编码我从中获取附件文件的文件夹名称?