docker 里面运行pyinstaller 打包有关troch的库报错OSError: Can‘t get source for <function sigmoid_focal_loss at 0x

Traceback (most recent call last):
  File "torch/_sources.py", line 21, in get_source_lines_and_file
  File "inspect.py", line 979, in getsourcelines
  File "inspect.py", line 798, in findsource
OSError: could not get source code

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "objRecognition.py", line 6, in 
  File "", line 991, in _find_and_load
  File "", line 975, in _find_and_load_unlocked
  File "", line 671, in _load_unlocked
  File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
  File "detectron2/engine/__init__.py", line 11, in 
  File "", line 991, in _find_and_load
  File "", line 975, in _find_and_load_unlocked
  File "", line 671, in _load_unlocked
  File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
  File "detectron2/engine/hooks.py", line 19, in 
  File "", line 991, in _find_and_load
  File "", line 975, in _find_and_load_unlocked
  File "", line 671, in _load_unlocked
  File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
  File "fvcore/nn/__init__.py", line 4, in 
  File "", line 991, in _find_and_load
  File "", line 975, in _find_and_load_unlocked
  File "", line 671, in _load_unlocked
  File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
  File "fvcore/nn/focal_loss.py", line 52, in 
  File "torch/jit/_script.py", line 1307, in script
  File "torch/jit/frontend.py", line 233, in get_jit_def
  File "torch/_sources.py", line 95, in parse_def
  File "torch/_sources.py", line 28, in get_source_lines_and_file
OSError: Can't get source for . TorchScript requires source access in order to carry out compilation, make sure original .py files are available.

docker 里面运行pyinstaller 打包有关troch的库报错OSError: Can‘t get source for <function sigmoid_focal_loss at 0x_第1张图片

解决办法

spec文件修改如下信息

# -*- mode: python ; coding: utf-8 -*-
import torch  # add
import torchvision  # add
import inspect  # add
import torch.jit  # add
block_cipher = None
from PyInstaller.utils.hooks import collect_data_files  # add


a = Analysis(
    ['main.py'],
    pathex=[],
    binaries=[],
    datas=[*collect_data_files("torch", include_py_files=True), *collect_data_files("fvcore", include_py_files=True), *collect_data_files("detectron2", include_py_files=True), *collect_data_files("torchvision", include_py_files=True)],  #modify
    hiddenimports=['sklearn.utils._typedefs', 'sklearn.utils._heap', 'sklearn.utils._sorting', 'sklearn.utils._vector_sentinel'],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=block_cipher,
    noarchive=False,
)


你可能感兴趣的:(docker,深度学习,容器)