首页 > 解决方案 > 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 )

标签: pyinstaller

解决方案


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))

推荐阅读