pyinstaller 打包 torch\_jit_internal.py:750: UserWarning: Unable to retrieve source for @torch.jit._ov

运行的时候不报错,但是打包以后,由于调用了pytorch,所以报了如下错误

torch\_jit_internal.py:750: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function _DenseLayer.forward at 0x0000012D8ED93310>.
  warnings.warn(f"Unable to retrieve source for @torch.jit._overload function: {func}.")
torch\_jit_internal.py:750: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function _DenseLayer.forward at 0x0000012D8EDAD550>.
  warnings.warn(f"Unable to retrieve source for @torch.jit._overload function: {func}.")
<super: <class 'PreviewQWindow'>, <PreviewQWindow object>>
<super: <class 'MainQWindow'>, <MainQWindow object>>
torch\_jit_internal.py:750: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function _DenseLayer.forward at 0x000001FF690D7310>.
  warnings.warn(f"Unable to retrieve source for @torch.jit._overload function: {func}.")
torch\_jit_internal.py:750: UserWarning: Unable to retrieve source for @torch.jit._overload function: <function _DenseLayer.forward at 0x000001FF690ED550>.
  warnings.warn(f"Unable to retrieve source for @torch.jit._overload function: {func}.")

pyinstaller 打包 torch\_jit_internal.py:750: UserWarning: Unable to retrieve source for @torch.jit._ov_第1张图片
从github的反馈来看,这并不算error,只是warning,程序可以正常执行,只是在控制台上不美观

有两种解决方法:

方法1:
打包的时候添加以下语句:
–hidden-import torch.jit

但我试了,并没有用


方法2
将torch文件里的这句话注释掉(外网也是这么干的,需要注意是对应虚拟环境里的torch,不要找错了)
路径:X:\Anaconda3\envs\(虚拟环境名)\Lib\site-packages\torch_jit_internal.py

打开_jit_internal.py,从warning可知,是在750行处报错,找到750行:
如下图所示:
pyinstaller 打包 torch\_jit_internal.py:750: UserWarning: Unable to retrieve source for @torch.jit._ov_第2张图片
将warnings.warn(f"Unable to retrieve source for @torch.jit._overload function: {func}.") 注释掉

这样重新打包就可以了

如果不带console输出控制台,也可以不改

你可能感兴趣的:(pytorch,深度学习)