I encountered a problem while trying to package a Python program. The error I got is:
FileNotFoundError: [Errno 2] No such file or directory: 'models\\lab3.pt'
I was trying to package files that include PyQt5 and the Yolov8 model. Whether I used Pyinstaller or cx_Freeze, I faced issues where the .pt file couldn't be found. I also tried compiling the corresponding .spec file, but it didn't include the .py file.
`
block_cipher = None
a = Analysis(
['T.py'],
pathex=['C:\Users\87181\Desktop\Feather_UI'],
binaries=[],
datas=[('C:\Users\87181\Desktop\Feather_UI\ultralytics\cfg\default.yaml', 'ultralytics\cfg'),
('C:\Users\87181\Desktop\Feather_UI\UiProgram\ui_sources.py', 'UiProgram'),
('C:\Users\87181\Desktop\Feather_UI\models\lab3.pt', 'models')],
hiddenimports=['ui_sources_rc'],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False
)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(
pyz,
a.scripts,
[],
exclude_binaries=True,
name='airway_seg',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True,
disable_windowed_traceback=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None )
coll = COLLECT(
exe,
a.binaries,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='T',
)
`
but still have error as:
C:\Users\87181\Desktop\Feather_UI\dist\T>airway_seg.exe Traceback (most recent call last): File "T.py", line 449, in <module> File "T.py", line 26, in __init__ File "T.py", line 43, in initialize File "ultralytics\models\yolo\model.py", line 23, in __init__ File "ultralytics\engine\model.py", line 152, in __init__ File "ultralytics\engine\model.py", line 241, in _load File "ultralytics\nn\tasks.py", line 856, in attempt_load_one_weight File "ultralytics\nn\tasks.py", line 782, in torch_safe_load File "torch\serialization.py", line 997, in load File "torch\serialization.py", line 444, in _open_file_like File "torch\serialization.py", line 425, in __init__ FileNotFoundError: [Errno 2] No such file or directory: 'models\\lab3.pt' [13984] Failed to execute script 'T' due to unhandled exception!
I encountered a problem while trying to package a Python program. The error I got is:
FileNotFoundError: [Errno 2] No such file or directory: 'models\\lab3.pt'I was trying to package files that include PyQt5 and the Yolov8 model. Whether I used Pyinstaller or cx_Freeze, I faced issues where the .pt file couldn't be found. I also tried compiling the corresponding .spec file, but it didn't include the .py file.
`
block_cipher = None
a = Analysis(
['T.py'],
pathex=['C:\Users\87181\Desktop\Feather_UI'],
binaries=[],
datas=[('C:\Users\87181\Desktop\Feather_UI\ultralytics\cfg\default.yaml', 'ultralytics\cfg'),
('C:\Users\87181\Desktop\Feather_UI\UiProgram\ui_sources.py', 'UiProgram'),
('C:\Users\87181\Desktop\Feather_UI\models\lab3.pt', 'models')],
hiddenimports=['ui_sources_rc'],
)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(
pyz,
a.scripts,
[],
exclude_binaries=True,
name='airway_seg',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True,
disable_windowed_traceback=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None )
coll = COLLECT(
exe,
a.binaries,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='T',
)
`
but still have error as:
C:\Users\87181\Desktop\Feather_UI\dist\T>airway_seg.exe Traceback (most recent call last): File "T.py", line 449, in <module> File "T.py", line 26, in __init__ File "T.py", line 43, in initialize File "ultralytics\models\yolo\model.py", line 23, in __init__ File "ultralytics\engine\model.py", line 152, in __init__ File "ultralytics\engine\model.py", line 241, in _load File "ultralytics\nn\tasks.py", line 856, in attempt_load_one_weight File "ultralytics\nn\tasks.py", line 782, in torch_safe_load File "torch\serialization.py", line 997, in load File "torch\serialization.py", line 444, in _open_file_like File "torch\serialization.py", line 425, in __init__ FileNotFoundError: [Errno 2] No such file or directory: 'models\\lab3.pt' [13984] Failed to execute script 'T' due to unhandled exception!