当前位置:网站首页>Pyuninstaller package exe cannot find the source code when running, function error oserror: could not get source code
Pyuninstaller package exe cannot find the source code when running, function error oserror: could not get source code
2022-04-23 21:02:00 【Top of the program】
Use today pyinstaller take Detectron2 A file of is packaged into exe, However, the following error occurred during the operation of the program
Traceback (most recent call last):
File "torch\_sources.py", line 21, in get_source_lines_and_file
sourcelines, file_lineno = inspect.getsourcelines(obj)
File "inspect.py", line 956, in getsourcelines
File "inspect.py", line 787, 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 "cell_analyse.py", line 8, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "detectron2\model_zoo\__init__.py", line 8, in <module>
from .model_zoo import get, get_config_file, get_checkpoint_url, get_config
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "detectron2\model_zoo\model_zoo.py", line 9, in <module>
from detectron2.modeling import build_model
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "detectron2\modeling\__init__.py", line 2, in <module>
from detectron2.layers import ShapeSpec
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "detectron2\layers\__init__.py", line 2, in <module>
from .batch_norm import FrozenBatchNorm2d, get_norm, NaiveSyncBatchNorm, CycleBatchNormList
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "detectron2\layers\batch_norm.py", line 4, in <module>
from fvcore.nn.distributed import differentiable_all_reduce
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "fvcore\nn\__init__.py", line 4, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "fvcore\nn\focal_loss.py", line 52, in <module>
File "torch\jit\_script.py", line 1307, in script
ast = get_jit_def(obj, obj.__name__)
File "torch\jit\frontend.py", line 233, in get_jit_def
parsed_def = parse_def(fn)
File "torch\_sources.py", line 95, in parse_def
sourcelines, file_lineno, filename = get_source_lines_and_file(fn, ErrorReport.call_stack())
File "torch\_sources.py", line 28, in get_source_lines_and_file
raise OSError(msg) from e
OSError: Can't get source for <function sigmoid_focal_loss at 0x000002038751F9D8>. TorchScript requires source access in order to carry out compilation, make sure original .py files are available.
[75064] Failed to execute script 'cell_analyse' due to unhandled exception!
This error is directly prompted as sigmoid_focal_loss The source code of this function is not found , The program to add source code is File “inspect.py”, line 787, in findsource, Further tracking code discovery can be done through getfile This function can find the specific modules to be added to the program , I added the following line to the code of this function , Print out which module has not been added .
def getfile(object):
"""Work out which source or compiled file an object was defined in."""
if ismodule(object):
if getattr(object, '__file__', None):
return object.__file__
raise TypeError('{!r} is a built-in module'.format(object))
if isclass(object):
if hasattr(object, '__module__'):
object = sys.modules.get(object.__module__)
if getattr(object, '__file__', None):
return object.__file__
raise TypeError('{!r} is a built-in class'.format(object))
if ismethod(object):
object = object.__func__
if isfunction(object):
object = object.__code__
**print(object)** **# Add this line of code here , Print out which source code is not added successfully **
if istraceback(object):
object = object.tb_frame
if isframe(object):
object = object.f_code
if iscode(object):
return object.co_filename
raise TypeError('module, class, method, function, traceback, frame, or '
'code object was expected, got {}'.format(
type(object).__name__))
Personally, I feel that this pit father's error is related to the loading of source code ,Detectron2 Used inspect This module , Load source code , Lead to Pyinstaller When analyzing File Dependencies , Did not add the relevant source code .
After adding the print code , Compile again to generate exe, Rerun , The results are as follows log
<code object norm at 0x0000020384365780, file "torch\functional.py", line 1309>
<code object sigmoid_focal_loss at 0x000002038750B390, file "fvcore\nn\focal_loss.py", line 7>
<code object sigmoid_focal_loss at 0x000002038750B390, file "fvcore\nn\focal_loss.py", line 7>
Traceback (most recent call last):
File "torch\_sources.py", line 21, in get_source_lines_and_file
sourcelines, file_lineno = inspect.getsourcelines(obj)
File "inspect.py", line 956, in getsourcelines
File "inspect.py", line 787, in findsource
OSError: could not get source code
So we can see that , yes fvcore This module has not been added to the feasible exe Under the table of contents . When I put... Under the source code base fvcore Copy to build exe After the directory , Run again , It's not in the newspaper fvcore Error not found , You can report the error that the source code of other modules cannot be found , I copied it , The program can run smoothly .
Of course, the formal solution should be through modification .spec file , Automatically add the dependent files to the compiled files when packaging , This step , You can refer to pyinstaller The official resolvent
版权声明
本文为[Top of the program]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/111/202204210545089993.html
边栏推荐
猜你喜欢
Write table of MySQL Foundation (create table)
Chrome 94 introduces the controversial idle detection API, which apple and Mozilla oppose
thinkphp5+数据大屏展示效果
go interface
Gsi-ecm digital platform for engineering construction management
Problem brushing plan -- dynamic programming (IV)
C, print the source program of beautiful bell triangle
Mysql database common sense storage engine
3-5通过XSS获取cookie以及XSS后台管理系统的使用
Google 尝试在 Chrome 中使用 Rust
随机推荐
How to play the guiding role of testing strategy
pytorch 1.7. The model saved by X training cannot be loaded in version 1.4 or earlier
opencv应用——以图拼图
深入探究ASP.NET Core读取Request.Body的正确方式
Create vs project with MATLAB
Awk example skills
Norm normalization in tensorflow and pytorch of records
pikachuxss如何获取cookie靶场,返回首页总是失败
浅谈数据库设计之三大范式
ubutnu20安装CenterNet
Question brushing plan -- backtracking method (I)
Win 11K in 100 days, super complete learning guide for job transfer test
Cmake project under vs2019: calculating binocular parallax using elas method
【SDU Chart Team - Core】SVG属性类设计之枚举
Identifier CV is not defined in opencv4_ CAP_ PROP_ FPS; CV_ CAP_ PROP_ FRAME_ COUNT; CV_ CAP_ PROP_ POS_ Frames problem
Thinking after learning to type
[SQL] string series 2: split a string into multiple lines according to specific characters
电脑越用越慢怎么办?文件误删除恢复方法
Explore ASP Net core read request The correct way of body
ROS学习笔记-----ROS的使用教程