解决pyinstaller打包后,运行程序时出现缺少plotly库问题

用pyinstaller打包tkinter程序,打包后运行exe是报如下错误:

搜索一阵发现是pyinstaller在打包的时候(StartRun.py我要打包的主程序文件)可能会漏掉一些三方库,就在打包的时候加上三方库的绝对路径:

pyinstaller StartRun.py -F -p C:\Python36\Lib\site-packages

发现打包完之后还是会报以上问题,继续搜索后用添加hook文件的方式可以解决(彻底解决了我的问题),修改方法:

1.找到C:\Python36\Lib\site-packages\PyInstaller\hooks,长这样:

2.需要在这里新建一个类似的文件hook-plotly.py,文件内容如下:

from PyInstaller.utils.hooks import collect_data_files

datas = collect_data_files('plotly')

3.然后重新打包,打包的时候切记把StartRun.py的同级目录下StartRun.spec文件删除(在打包的时候会自动生成,如果不删除之前不成功的内容还是缓存在的),打包过程中会看到添加了plotly库:

# -*- mode: python ; coding: utf-8 -*- a = Analysis( ['run_app_akshare.py'], pathex=['E:/01_MyData/xssl_codes/01_xssl_project/99_hobby/04_小工具开发/集成工具/打包测试2'], binaries=[], datas=[ ('myapp_akshare.py', '.'), ('favicon.ico', '.'), # streamlit 静态资源 ("C:/Users/xiaoq/AppData/Local/Programs/Python/venv/dgrxlh/Lib/site-packages/streamlit/static", "streamlit/static"), ("C:/Users/xiaoq/AppData/Local/Programs/Python/venv/dgrxlh/Lib/site-packages/streamlit/runtime", "streamlit/runtime"), # 必要的 .dist-info 目录(streamlit、pandas、pyarrow 等) ("C:/Users/xiaoq/AppData/Local/Programs/Python/venv/dgrxlh/Lib/site-packages/streamlit-1.46.1.dist-info", "streamlit-1.46.1.dist-info"), ("C:/Users/xiaoq/AppData/Local/Programs/Python/venv/dgrxlh/Lib/site-packages/pandas-*.dist-info", "."), # 可选 ("C:/Users/xiaoq/AppData/Local/Programs/Python/venv/dgrxlh/Lib/site-packages/pyarrow-*.dist-info", "."), # 可选 ("C:/Users/xiaoq/AppData/Local/Programs/Python/venv/dgrxlh/Lib/site-packages/akshare/file_fold/calendar.json", "akshare/file_fold"), ('C:/Users/xiaoq/AppData/Local/Programs/Python/Python311/Lib/encodings', 'encodings'), ("C:/Users/xiaoq/AppData/Local/Programs/Python/Python311/DLLs", "DLLs"), ], hiddenimports=[ 'plotly', 'plotly.graph_objs', 'pandas', 'xlsxwriter', 'akshare','akshare', 'encodings', 'codecs','encodings.aliases', 'encodings.utf_8', 'sklearn', 'scipy', 'openpyxl', 'pyarrow', 'numpy', 'streamlit', 'requests','uuid', 'streamlit.runtime', 'streamlit.web', 'streamlit.web.bootstrap' ], hookspath=['./hooks'], hooksconfig={}, runtime_hooks=[], excludes=[], noarchive=False, optimize=0, ) pyz = PYZ(a.pure) exe = EXE( pyz, a.scripts, a.binaries, a.datas, [], name='打工人学量化ETF组合分析器', debug=False, bootloader_ignore_signals=False, strip=False, upx=True, upx_exclude=[], runtime_tmpdir=None, console=True, disable_windowed_traceback=False, argv_emulation=False, target_arch=None, codesign_identity=None, entitlements_file=None, icon=['favicon.ico'], )
07-17
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值