-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pytorch OSError: could not get source code #5729
Comments
Duplicate of #5673. |
The comment #4764 (comment) should work in combination with So can you try installing and using that: |
yes, i'm tried install but still get same error ;( is my spec file wrong ? |
Well, for either approach to work (#5697 that loads collected py files directly, or the From your traceback, I can see (local) packages such as |
yes great!, it work! i'm collect fvcore and detectron2 package using collect_source_files this my spec file import torch a = Analysis(['../detector/main.py'],
pyz = PYZ(a.pure, a.zipped_data, |
I'm using pyinstaller package pytorch is successful but when i run binary file get error
Traceback (most recent call last):
File "torch/_utils_internal.py", line 49, in get_source_lines_and_file
sourcelines, file_lineno = inspect.getsourcelines(obj)
File "inspect.py", line 967, 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 "detector/main.py", line 138, in
File "detector/main.py", line 31, in init
File "importlib/init.py", line 127, in import_module
File "", line 1014, in _gcd_import
File "", line 991, in _find_and_load
File "", line 975, in _find_and_load_unlocked
File "", line 671, in _load_unlocked
File "PyInstaller/loader/pyimod03_importers.py", line 531, in exec_module
File "detector/detect_0.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/pyimod03_importers.py", line 531, 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/pyimod03_importers.py", line 531, in exec_module
File "detectron2/engine/hooks.py", line 14, 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/pyimod03_importers.py", line 531, 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/pyimod03_importers.py", line 531, in exec_module
File "fvcore/nn/focal_loss.py", line 50, in
File "torch/jit/_script.py", line 936, in script
ast = get_jit_def(obj, obj.name)
File "torch/jit/frontend.py", line 197, in get_jit_def
sourcelines, file_lineno, filename = get_source_lines_and_file(fn, torch._C.ErrorReport.call_stack())
File "torch/_utils_internal.py", line 56, in get_source_lines_and_file
raise OSError(msg) from e
OSError: Can't get source for <function sigmoid_focal_loss at 0x7f931dd6e160>. TorchScript requires source access in order to carry out compilation, make sure original .py files are available.
[7269] Failed to execute script main
########################################################################
development environment information:
python 3.8.5
pyinstaller 4.2
platform Ubuntu 18.04.5 LTS
torch 1.7.1
torchvision 0.8.2
#########################################################################
main.spec
-- mode: python ; coding: utf-8 --
import torch
import inspect
block_cipher = None
excluded_modules = ['torch.distributions']
def collect_source_files(modules):
datas = []
for module in modules:
source = inspect.getsourcefile(module)
dest = f"src.{module.name}" # use "src." prefix
datas.append((source, dest))
return datas
source_files = collect_source_files([torch]) # return same structure as
collect_data_files()
source_files_toc = TOC((name, path, 'DATA') for path, name in source_files)
a = Analysis(['../detector/main.py'],
pathex=['/data1/kazhen'],
binaries=[],
datas=[],
hiddenimports=['detector.detect_0', 'detector.detect_1', 'detector.detect_2', 'detector.detect_3',
'detector.detect_4', 'detector.detect_5', 'detector.detectron2', 'torch'],
hookspath=[],
runtime_hooks=[],
excludes=None,
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data, source_files_toc,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
[],
exclude_binaries=True,
name='detect_main',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='detect_main')
i tried issue https://github.com/pyinstaller/pyinstaller/issues/4764#issuecomment-633777790 but it doesn't work.
how can i fix this error ?
The text was updated successfully, but these errors were encountered: