pyinstaller和py2exe是常用的.py打包.exe工具,但打包引用了pyecharts的代码时总是报错。虽然.exe打包成功,但双击运行时闪退,报错:
[Errno 2] No such file or directory: 'C:\Users\ADMINI~1\AppData\Local\Temp\_MEI一串数字\pyecharts\datasets\map_filename.json
这是因为打包时修改了.\site-packages\pyecharts\datasets\_init_.py里的__HERE变量,使其找不到map_filename.json
网上有解决方案是重新源码安装pyecharts,可能有用,下面是我亲测有效的解决办法:
解决办法:
1.在.\Lib\site-packages\PyInstaller\hooks路径下新建一个hook-pyecharts.py,里面写入
from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('pyecharts')
2.在用Pyinstaller打包时,加入两个命令参数:
pyinstaller --add-data="D:\Program Files (x86)\PycharmProjects\map\Lib\site-packages\pyecharts;pyechats" --hidden-import=pyecharts.render.engine -F GUI.py
生成的.exe便可正常运行了