python 使用pyinstaller 打包资源进exe

# -*- coding: utf-8 -*-#
# -------------------------------------------------------------------------------
# Name:         资源打包
# Author:       yunhgu
# Date:         2022/3/10 15:07
# Description: 
# -------------------------------------------------------------------------------
import os
import sys


def resource_path(relative_path):
    """
    :param relative_path:
    :return:# 生成资源文件目录访问路径
    """
    if getattr(sys, 'frozen', False):  # 是否Bundle Resource
        base_path = sys._MEIPASS
    else:
        base_path = os.path.abspath(".")
    return os.path.join(base_path, relative_path)


file = resource_path(r'res\test.txt')
print(file)

image

# -*- mode: python ; coding: utf-8 -*-


block_cipher = None


a = Analysis(['资源打包.py'],
             pathex=[],
             binaries=[],
             datas=[('res','res')],# 修改这个地方
             hiddenimports=[],
             hookspath=[],
             hooksconfig={},
             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='资源打包',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          upx_exclude=[],
          runtime_tmpdir=None,
          console=True,
          disable_windowed_traceback=False,
          target_arch=None,
          codesign_identity=None,
          entitlements_file=None , icon='D:\\Miniconda3\\Lib\\site-packages\\gooey\\images\\program_icon.ico')

image

posted @ 2022-03-10 15:14  不能说的秘密  阅读(182)  评论(0编辑  收藏  举报