jetson pyinstaller打包python相关报错

9 篇文章 0 订阅
2 篇文章 0 订阅

下载pyinstaller

sudo pip3 install PyInstaller

 相关参数说明:

pyinstaller -D -c xxx.py       

# 常用参数说明
-F :生成结果是一个exe文件,所有的第三方依赖、资源和代码均被打包进该exe内
-D :生成结果是一个目录,各种第三方依赖、资源和exe同时存储在该目录
-w :不显示命令行窗口
-c :显示命令行窗口

生成3个文件:
build:当于PyInstaller的工作空间,PyInstaller运行相关的文件和日志都在这个文件夹中,打包完成后可以直接删除。
dist:可执行文件生成地方
xxx.spec:pyinstaller生成的配置文件,下次打包时,可以不运行上面带参数的命令,而直接运行:
pyinstaller xxx.spec

 终端显示:Building EXE from EXE-00.toc completed successfully,表示打包成功。

执行打包后的文件,进入dist文件夹,执行文件

./文件名

相关报错以及解决方案:

(1)ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions.Check OpenCV installation.

Traceback (most recent call last):
  File "demo_4.py", line 16, in <module>
    import cv2
  File "PyInstaller/loader/pyimod03_importers.py", line 495, in exec_module
  File "cv2/__init__.py", line 89, in <module>
  File "cv2/__init__.py", line 79, in bootstrap
  File "PyInstaller/loader/pyimod03_importers.py", line 495, in exec_module
  File "cv2/__init__.py", line 89, in <module>
  File "cv2/__init__.py", line 23, in bootstrap
ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.
[10187] Failed to execute script 'demo_4' due to unhandled exception!

解决:pyinstaller和cv2版本存在兼容问题,初始pyinstaller==4.10,降低版本至pyinstaller==4.7,下载opencv-python==4.5.3.56,再次打包可避免此错误。

(2)RuntimError: Error in dlopen or dlsym:libcaffe2_nvrtc.so: cannot open shared object file: No such file or directory 

 解决:查找到libcaffe2_nvrtc.so,将其移动至/usr/lib下重新打包即可。

(3)Error: Cannot open self xx or archive xx.pkg

解决:程序没有打包好,重新执行命令打包即可 

(4)Error: lllegal instruction(core dumped)

终端运行:

sudo gedit ~/.bashrc

 末尾添加环境变量,保存并关闭文件;

export OPENBLAS_CORETYPE=ARMV8

 终端运行source ~/.bashrc;

source ~/.bashrc

(5)OSError: could not get source code

[9407] WARNING: file already exists but should not: /tmp/_MEIa1SwDt/torch/_C.cpython-36m-aarch64-linux-gnu.so
[9407] WARNING: file already exists but should not: /tmp/_MEIa1SwDt/torch/_dl.cpython-36m-aarch64-linux-gnu.so
/tmp/_MEIa1SwDt/torchvision/ops/boxes.py:101: UserWarning: This overload of nonzero is deprecated:
	nonzero()
Consider using one of the following signatures instead:
	nonzero(*, bool as_tuple) (Triggered internally at  ../torch/csrc/utils/python_arg_parser.cpp:766.)
Traceback (most recent call last):
  File "torch/_utils_internal.py", line 46, in get_source_lines_and_file
  File "inspect.py", line 955, in getsourcelines
  File "inspect.py", line 786, in findsource
OSError: could not get source code

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "demo_4.py", line 257, in <module>
    model(input)
  File "torch/nn/modules/module.py", line 722, in _call_impl
  File "torchvision/models/detection/generalized_rcnn.py", line 98, in forward
  File "torch/nn/modules/module.py", line 722, in _call_impl
  File "torchvision/models/detection/rpn.py", line 493, in forward
  File "torchvision/models/detection/rpn.py", line 410, in filter_proposals
  File "torch/jit/__init__.py", line 1599, in wrapper
  File "torch/jit/__init__.py", line 1547, in script
  File "torch/jit/frontend.py", line 164, in get_jit_def
  File "torch/_utils_internal.py", line 53, in get_source_lines_and_file
OSError: Can't get source for <function batched_nms at 0x7f118c00d0>. TorchScript requires source access in order to carry out compilation, make sure original .py files are available. Original error: could not get source code
[10462] Failed to execute script 'demo_4' due to unhandled exception!

解决:在import torch 上面加入以下代码,在报错的模块里加入代码,报错文件一般与需要打包的文件相同。下面参考链接中另有方法,可参考。

def script_method(fn, _rcb=None):
    return fn


def script(obj, optimize=True, _frames_up=0, _rcb=None):
    return obj


import torch.jit
script_method1 = torch.jit.script_method
script1 = torch.jit.script
torch.jit.script_method = script_method
torch.jit.script = script

 相关参考:

(1)Python | 利用pyinstaller封装代码 - 知乎

(2)pyinstaller打包错误:ERROR: recursion is detected during loading of “cv2“ binary extensions._pyinstaller 495_HenryFar的博客-CSDN博客

(3)python打包成exe程序_pingfan2014的博客-CSDN博客 

(4) jetson nano 报错Illegal instruction(core dumped)_郭庆汝的博客-CSDN博客

(5)pyinstaller打包错误:OSError: Can‘t get source for <function sigmoid_focal_loss at 0x00000174BE600F70>._pyimod02_importers_a little cabbage的博客-CSDN博客

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值