自己在尝试着封装自己的程序,遇见了缺少dll包,这个倒是好解决,根据告警信息去相应的文件包下去找道包,但是我被一个告警死死困扰住了。
封装时信息如下:
封装时出现的:
C:\Users\Dell\Desktop\wheat>pyinstaller -p D:\python37\Lib\site-packages\torch\lib -F predict.py
95 INFO: PyInstaller: 4.5.1
96 INFO: Python: 3.7.8
96 INFO: Platform: Windows-10-10.0.19041-SP0
98 INFO: wrote C:\Users\Dell\Desktop\wheat\predict.spec
104 INFO: UPX is not available.
107 INFO: Extending PYTHONPATH with paths
['C:\\Users\\Dell\\Desktop\\wheat',
'D:\\python37\\Lib\\site-packages\\torch\\lib',
'C:\\Users\\Dell\\Desktop\\wheat']
393 INFO: checking Analysis
393 INFO: Building Analysis because Analysis-00.toc is non existent
394 INFO: Initializing module dependency graph...
397 INFO: Caching module graph hooks...
412 INFO: Analyzing base_library.zip ...
2401 INFO: Processing pre-find module path hook distutils from 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'.
2402 INFO: distutils: retargeting to non-venv dir 'd:\\python37\\lib'
3500 INFO: Caching module dependency graph...
3734 INFO: running Analysis Analysis-00.toc
3736 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by d:\python37\python.exe
3878 INFO: Analyzing C:\Users\Dell\Desktop\wheat\predict.py
6319 INFO: Processing pre-find module path hook site from 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-site.py'.
6320 INFO: site: retargeting to fake-dir 'd:\\python37\\lib\\site-packages\\PyInstaller\\fake-modules'
7473 INFO: Processing pre-safe import module hook setuptools.extern.six.moves from 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-setuptools.extern.
six.moves.py'.
12080 INFO: Processing pre-safe import module hook six.moves from 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-six.moves.py'.
12394 INFO: Processing module hooks...
12395 INFO: Loading module hook 'hook-torch.py' from 'd:\\python37\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
12614 INFO: Loading module hook 'hook-torchvision.ops.py' from 'd:\\python37\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
12615 INFO: Loading module hook 'hook-difflib.py' from 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks'...
12618 INFO: Loading module hook 'hook-distutils.py' from 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks'...
12618 INFO: Loading module hook 'hook-distutils.util.py' from 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks'...
12621 INFO: Loading module hook 'hook-encodings.py' from 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks'...
12726 INFO: Loading module hook 'hook-heapq.py' from 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks'...
12729 INFO: Loading module hook 'hook-importlib_metadata.py' from 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks'...
12731 INFO: Loading module hook 'hook-lib2to3.py' from 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks'...
12887 INFO: Loading module hook 'hook-multiprocessing.util.py' from 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks'...
12891 INFO: Loading module hook 'hook-numpy.py' from 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks'...
12962 INFO: Import to be excluded not found: 'f2py'
12985 INFO: Loading module hook 'hook-numpy._pytesttester.py' from 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks'...
12989 INFO: Loading module hook 'hook-pickle.py' from 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks'...
12992 INFO: Loading module hook 'hook-PIL.Image.py' from 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks'...
13330 INFO: Loading module hook 'hook-PIL.ImageFilter.py' from 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks'...
13334 INFO: Loading module hook 'hook-PIL.py' from 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks'...
13347 INFO: Loading module hook 'hook-PIL.SpiderImagePlugin.py' from 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks'...
13350 INFO: Loading module hook 'hook-pkg_resources.py' from 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks'...
13876 INFO: Processing pre-safe import module hook win32com from 'd:\\python37\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\pre_safe_import_module\\hook-win32com.py'.
13931 WARNING: Hidden import "pkg_resources.markers" not found!
13935 INFO: Loading module hook 'hook-setuptools.py' from 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks'...
14558 INFO: Loading module hook 'hook-sqlite3.py' from 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks'...
14664 INFO: Loading module hook 'hook-sysconfig.py' from 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks'...
14664 INFO: Loading module hook 'hook-win32ctypes.core.py' from 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks'...
14842 INFO: Loading module hook 'hook-xml.dom.domreg.py' from 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks'...
14843 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks'...
14844 INFO: Loading module hook 'hook-xml.py' from 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks'...
14845 INFO: Loading module hook 'hook-_tkinter.py' from 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks'...
15005 INFO: checking Tree
15006 INFO: Building Tree because Tree-00.toc is non existent
15006 INFO: Building Tree Tree-00.toc
15045 INFO: checking Tree
15046 INFO: Building Tree because Tree-01.toc is non existent
15046 INFO: Building Tree Tree-01.toc
15147 INFO: checking Tree
15148 INFO: Building Tree because Tree-02.toc is non existent
15148 INFO: Building Tree Tree-02.toc
15154 INFO: Loading module hook 'hook-setuptools.msvc.py' from 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks'...
15197 INFO: Looking for ctypes DLLs
15279 INFO: Analyzing run-time hooks ...
15288 INFO: Including run-time hook 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgutil.py'
15291 INFO: Including run-time hook 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_inspect.py'
15293 INFO: Including run-time hook 'd:\\python37\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_multiprocessing.py'
15307 INFO: Looking for dynamic libraries
16663 INFO: Looking for eggs
16664 INFO: Using Python library d:\python37\python37.dll
16664 INFO: Found binding redirects:
[]
16673 INFO: Warnings written to C:\Users\Dell\Desktop\wheat\build\predict\warn-predict.txt
16814 INFO: Graph cross-reference written to C:\Users\Dell\Desktop\wheat\build\predict\xref-predict.html
16903 INFO: checking PYZ
16903 INFO: Building PYZ because PYZ-00.toc is non existent
16903 INFO: Building PYZ (ZlibArchive) C:\Users\Dell\Desktop\wheat\build\predict\PYZ-00.pyz
18379 INFO: Building PYZ (ZlibArchive) C:\Users\Dell\Desktop\wheat\build\predict\PYZ-00.pyz completed successfully.
18402 INFO: checking PKG
18402 INFO: Building PKG because PKG-00.toc is non existent
18403 INFO: Building PKG (CArchive) PKG-00.pkg
92717 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
92786 INFO: Bootloader d:\python37\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
92786 INFO: checking EXE
92786 INFO: Building EXE because EXE-00.toc is non existent
92787 INFO: Building EXE from EXE-00.toc
92790 INFO: Copying icons from ['d:\\python37\\lib\\site-packages\\PyInstaller\\bootloader\\images\\icon-console.ico']
92792 INFO: Writing RT_GROUP_ICON 0 resource with 104 bytes
92792 INFO: Writing RT_ICON 1 resource with 3752 bytes
92792 INFO: Writing RT_ICON 2 resource with 2216 bytes
92793 INFO: Writing RT_ICON 3 resource with 1384 bytes
92793 INFO: Writing RT_ICON 4 resource with 37019 bytes
92793 INFO: Writing RT_ICON 5 resource with 9640 bytes
92794 INFO: Writing RT_ICON 6 resource with 4264 bytes
92794 INFO: Writing RT_ICON 7 resource with 1128 bytes
92803 INFO: Updating manifest in C:\Users\Dell\Desktop\wheat\build\predict\run.exe.cuno9dtu
92805 INFO: Updating resource type 24 name 1 language 0
92817 INFO: Appending archive to EXE C:\Users\Dell\Desktop\wheat\dist\predict.exe
142767 INFO: Building EXE from EXE-00.toc completed successfully.
运行时出现的问题:
[13472] WARNING: file already exists but should not: C:\Users\Dell\AppData\Local\Temp\_MEI134722\torch\_C.cp37-win_amd64.pyd
Traceback (most recent call last):
File "predict.py", line 3, 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 546, in exec_module
File "wheat.py", line 9, 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 546, in exec_module
File "utils\utils.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 546, in exec_module
File "torchvision\__init__.py", line 1, 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 546, in exec_module
File "torchvision\models\__init__.py", line 12, 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 546, in exec_module
File "torchvision\models\detection\__init__.py", line 1, 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 546, in exec_module
File "torchvision\models\detection\faster_rcnn.py", line 7, 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 546, in exec_module
File "torchvision\ops\misc.py", line 135, in <module>
File "torchvision\ops\misc.py", line 148, in FrozenBatchNorm2d
File "torch\jit\__init__.py", line 1204, in script_method
File "torch\jit\frontend.py", line 156, in get_jit_def
File "inspect.py", line 955, in getsourcelines
File "inspect.py", line 786, in findsource
OSError: could not get source code
[8728] Failed to execute script 'predict' due to unhandled exception!
根据运行告警的最后几条,jit 的问题,我是使用 torch==1.2 和 torchvision==0.4 CPU版本的(CPU版本通用)
也曾多次查阅网上别人介绍的问题解决方案,终是没能解决(第一条告警信息可以忽略)
最后还是翻墙出去找到了答案
方案一:
在代码开始的地方输入:
def script_method(fn, _rcb=None):
return fn
def script(obj, optimize=True, _frames_up=0, _rcb=None):
return obj
import torch.jit
torch.jit.script_method = script_method
torch.jit.script = script
方案二:
在os后面,在torch torchvision前面加上
os.environ["PYTORCH_JIT"] = "0"
网友评论