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)
# -*- 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')
不论你在什么时候开始,重要的是开始之后就不要停止。
不论你在什么时候结束,重要的是结束之后就不要悔恨。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律