将ico图标等资源打包到exe中的方法



pyinstaller将ico图标等资源打包到exe中的方法

                /

  • 编辑
  • 删除


代码图标获取地址改为一下方法    ico文件夹和createBankCard.pyw文件平级

 QtCore.QTextCodec.setCodecForCStrings(QtCore.QTextCodec.codecForName("utf-8"))

    sys.exit(app.exec_())   

 

#修正ico图标路径

def resource_path(relative):
    if hasattr(sys, "_MEIPASS"):
        return os.path.join(sys._MEIPASS,relative)
    return os.path.join(relative)


修改打包的spec文件

# -*- mode: python -*-

block_cipher = None


a = Analysis(['cpipeMain.py'],
             pathex=['E:\\21_23_log\\SF\\script'],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          [('my.ico','E:\\21_23_log\\SF\script\\my.ico','DATA')],
          name='cpipeMain',
          debug=False,
          strip=False,
          upx=True,
          console=False , icon='my.ico')

a.datas,下面添加   [('\\ico\\bank.ico','E:\\python\\ico\\bank.ico','DATA')],

然后在执行打包命令:pyinstaller xxx.spec即可。

你可能感兴趣的:(pyqt,pyinstaller)