pyinstaller 打包python程序为可执行exe文件,js报错问题

错误描述

工作需要,想把一个py文件转换成可执行exe文件,正常使用 pyinstaller ui_app.py --onefile --icon=app_icon.ico转换后,打开dist文件夹内的exe文件,出现闪退现象,报错提示一下内容。

Traceback (most recent call last):
  File "ui.py", line 6, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
  File "mne\__init__.py", line 99, in <module>
    from .report import Report, open_report
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
  File "mne\report\__init__.py", line 1, in <module>
    from .report import Report, open_report, _ReportScraper
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
  File "mne\report\report.py", line 101, in <module>
    JAVASCRIPT = (html_include_dir / 'report.js').read_text(encoding='utf-8')
  File "pathlib.py", line 1266, in read_text
  File "pathlib.py", line 1252, in open
  File "pathlib.py", line 1120, in _opener
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\userName\\AppData\\Local\\Temp\\_MEI208682\\mne\\report\\js_and_css\\report.js

问了问Chatgpt:
它告诉我以下方法:

This error suggests that the executable file is unable to find the report.js file required by the mne module. It seems that the file is not being included in the executable. You can try the following solutions to fix the issue:

Specify the --add-data option while running the PyInstaller command. For example, if the report.js file is located in the mne/report/js_and_css/ directory, you can add the following option: –add-data “mne/report/js_and_css/report.js;./mne/report/js_and_css/”. This tells PyInstaller to include the report.js file in the executable.

If the above solution does not work, you can manually copy the report.js file to the dist directory after building the executable. You can find the dist directory in the same directory where your Python script is located. Once you copy the file, try running the executable again.

If none of the above solutions work, you can try using the --onefile option while running the PyInstaller command. This will create a single executable file instead of multiple files, which might help in resolving the issue.

I hope one of these solutions helps you to fix the issue.
尝试无果。
后面看到CSDN上的一篇博客:https://blog.csdn.net/weixin_43865152/article/details/93781051
提到了他是如何解决的。

1 删除原来生成的东西

2 使用半打包命令

pyinstaller -D -w -i app_icon.ico ui.py

-w,是只打开ui界面,不显示cmd命令行。
-i,是加载图标

3 将刚才不能打包进去的依赖包的文件夹手动放入ui.exe所在的文件夹,一般在dist下(也可能还有一层文件夹)

例如将:
D:\anaconda\envs\DataManage\Lib\site-packages\mne_bids
D:\anaconda\envs\DataManage\Lib\site-packages\mne
放入 C:\Users\suername\PycharmProjects\Manage_project\dist

4 再次尝试打开ui,应该就可以了。

参考

https://blog.csdn.net/huhu1986/article/details/109388027
https://blog.csdn.net/weixin_43865152/article/details/93781051

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值