“NoneType”对象没有属性“encoding”

问题描述 投票:0回答:1

我正在举办一个舞会,试图从

exe
文件创建
py
文件。我正在使用 pyinstaller 创建带有参数
--onefile --noconsole
的 exe 文件。

[错误](https://i.stack.imgur.com/91bP8.png)

这是构建期间终端上的消息

255 INFO: PyInstaller: 6.3.0
255 INFO: Python: 3.10.11
262 INFO: Platform: Windows-10-10.0.22635-SP0
262 INFO: wrote D:\PythonProjects\FruitDetectv2\Detect.spec
265 INFO: Extending PYTHONPATH with paths
['D:\\PythonProjects\\FruitDetectv2']
4598 INFO: checking Analysis
4599 INFO: Building Analysis because Analysis-00.toc is non existent
4599 INFO: Initializing module dependency graph...
4600 INFO: Caching module graph hooks...
4614 INFO: Analyzing base_library.zip ...
5200 INFO: Loading module hook 'hook-heapq.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
5251 INFO: Loading module hook 'hook-encodings.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
6257 INFO: Loading module hook 'hook-pickle.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
7134 INFO: Caching module dependency graph...
7226 INFO: Running Analysis Analysis-00.toc
7226 INFO: Looking for Python shared library...
7233 INFO: Using Python shared library: C:\Users\Sahayog\AppData\Local\Programs\Python\Python310\python310.dll
7233 INFO: Analyzing D:\PythonProjects\FruitDetectv2\Detect.py
7276 INFO: Loading module hook 'hook-multiprocessing.util.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
7397 INFO: Loading module hook 'hook-xml.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
7574 INFO: Loading module hook 'hook-cv2.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
8660 INFO: Loading module hook 'hook-numpy.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\Lib\\site-packages\\numpy\\_pyinstaller'...
9071 INFO: Loading module hook 'hook-difflib.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
9404 INFO: Loading module hook 'hook-platform.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
9438 INFO: Loading module hook 'hook-sysconfig.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
9803 INFO: Loading module hook 'hook-psutil.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
11074 INFO: Loading module hook 'hook-torch.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
64065 WARNING: Failed to collect submodules for 'torch.utils.tensorboard' because importing 'torch.utils.tensorboard' raised: ModuleNotFoundError: No module named 'tensorboard'
[2024-01-18 03:26:43,591] torch.distributed.elastic.multiprocessing.redirects: [WARNING] NOTE: Redirects are currently not supported in Windows or MacOs.
84927 INFO: hook-torch: raising recursion limit to 5000
84964 INFO: Loading module hook 'hook-packaging.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
85016 INFO: Loading module hook 'hook-pkg_resources.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
86686 INFO: Loading module hook 'hook-sympy.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
87502 INFO: Loading module hook 'hook-matplotlib.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
87978 INFO: Processing pre-safe import module hook gi from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-gi.py'.
88098 INFO: Loading module hook 'hook-PIL.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
88166 INFO: Loading module hook 'hook-PIL.Image.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
88802 INFO: Loading module hook 'hook-PIL.ImageFilter.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
89286 INFO: Loading module hook 'hook-jinja2.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
90714 INFO: Processing pre-safe import module hook six.moves from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-six.moves.py'.
91557 INFO: Loading module hook 'hook-matplotlib.backends.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
91745 INFO: Loading module hook 'hook-certifi.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
97474 INFO: Loading module hook 'hook-scipy.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
97938 INFO: Loading module hook 'hook-scipy.sparse.csgraph.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
98002 INFO: Loading module hook 'hook-scipy.linalg.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
99404 INFO: Loading module hook 'hook-scipy.spatial.transform.rotation.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
102815 INFO: Loading module hook 'hook-xml.dom.domreg.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
105252 INFO: Loading module hook 'hook-pandas.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
107296 INFO: Loading module hook 'hook-pytz.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
108297 INFO: Loading module hook 'hook-pandas.io.formats.style.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
111067 INFO: Loading module hook 'hook-pandas.plotting.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
112085 INFO: Loading module hook 'hook-sqlite3.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
113063 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
118580 INFO: Loading module hook 'hook-torchvision.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
118677 INFO: Loading module hook 'hook-torchvision.io.image.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
119283 INFO: Loading module hook 'hook-charset_normalizer.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
119609 INFO: Loading module hook 'hook-torchaudio.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
127016 INFO: Loading module hook 'hook-scipy.io.matlab.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
129601 INFO: Loading module hook 'hook-setuptools.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
130836 INFO: Processing pre-safe import module hook distutils from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-distutils.py'.
130837 INFO: Processing pre-find module path hook distutils from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'.
131138 INFO: Loading module hook 'hook-distutils.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
131178 INFO: Loading module hook 'hook-distutils.util.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
131933 INFO: Processing pre-safe import module hook win32com from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\pre_safe_import_module\\hook-win32com.py'.
137390 INFO: Processing pre-safe import module hook tensorflow from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\pre_safe_import_module\\hook-tensorflow.py'.
137940 INFO: Processing module hooks...
143458 INFO: Loading module hook 'hook-matplotlib.backends.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
143459 INFO: Matplotlib backend selection method: automatic discovery of used backends
143471 INFO: Discovered Matplotlib backend(s) via `matplotlib.use()` call in module 'sympy.testing.runtests': ['Agg', 'Agg']
143533 INFO: The following Matplotlib backends were discovered by scanning for `matplotlib.use()` calls: ['Agg']. If your backend of choice is not in this list, either add a `matplotlib.use()` call to your code, or configure the backend collection via hook options (see: https://pyinstaller.org/en/stable/hooks-config.html#matplotlib-hooks).
143533 INFO: Selected matplotlib backends: ['Agg']
143991 INFO: Loading module hook 'hook-PIL.SpiderImagePlugin.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
144328 INFO: Loading module hook 'hook-scipy.special._ellip_harm_2.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
144328 INFO: Loading module hook 'hook-scipy.special._ufuncs.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
144328 INFO: Loading module hook 'hook-scipy.stats._stats.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
144352 INFO: Loading module hook 'hook-setuptools.msvc.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
144755 INFO: Loading module hook 'hook-setuptools._distutils.command.check.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
144871 INFO: Loading module hook 'hook-_tkinter.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
144871 INFO: checking Tree
144871 INFO: Building Tree because Tree-00.toc is non existent
144872 INFO: Building Tree Tree-00.toc
144937 INFO: checking Tree
144937 INFO: Building Tree because Tree-01.toc is non existent
144937 INFO: Building Tree Tree-01.toc
144946 INFO: checking Tree
144946 INFO: Building Tree because Tree-02.toc is non existent
144946 INFO: Building Tree Tree-02.toc
145002 INFO: Performing binary vs. data reclassification (1784 entries)
145610 INFO: Looking for ctypes DLLs
145710 WARNING: Ignoring /usr/lib64/libgomp.so.1 imported from D:\PythonProjects\FruitDetectv2\.venv\lib\site-packages\torch\_inductor\codecache.py - only basenames are supported with ctypes imports!
145764 INFO: Analyzing run-time hooks ...
145789 INFO: Including run-time hook 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_inspect.py'
145791 INFO: Including run-time hook 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgres.py'
145795 INFO: Including run-time hook 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgutil.py'
145797 INFO: Processing pre-find module path hook _pyi_rth_utils from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-_pyi_rth_utils.py'.
145800 INFO: Loading module hook 'hook-_pyi_rth_utils.py' from 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks'...
145801 INFO: Including run-time hook 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth__tkinter.py'
145802 INFO: Including run-time hook 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_multiprocessing.py'
145805 INFO: Including run-time hook 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_mplconfig.py'
145813 INFO: Including run-time hook 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_setuptools.py'
145969 INFO: Looking for dynamic libraries
D:\PythonProjects\FruitDetectv2\.venv\lib\site-packages\PyInstaller\building\build_main.py:194: UserWarning: The numpy.array_api submodule is still experimental. See NEP 47.
  __import__(package)
[2024-01-18 03:27:55,180] torch.distributed.elastic.multiprocessing.redirects: [WARNING] NOTE: Redirects are currently not supported in Windows or MacOs.
156574 INFO: Extra DLL search directories (AddDllDirectory): ['D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\numpy.libs', 'D:\\PythonProjects\\FruitDetectv2\\.venv\\Lib\\site-packages\\cv2\\../../x64/vc14/bin', '
D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torch\\lib', 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\matplotlib.libs', 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\matplotli
b.libs', 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchvision', 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchvision', 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\to
rchvision', 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchvision', 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\pandas.libs', 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\scipy.libs']
156575 INFO: Extra DLL search directories (PATH): ['D:\\PythonProjects\\FruitDetectv2\\.venv\\Lib\\site-packages\\cv2\\../../x64/vc14/bin']
160758 WARNING: Library not found: could not resolve 'avcodec-60.dll', dependency of 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchaudio\\lib\\libtorchaudio_ffmpeg6.pyd'.
160759 WARNING: Library not found: could not resolve 'avutil-58.dll', dependency of 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchaudio\\lib\\libtorchaudio_ffmpeg6.pyd'.
160760 WARNING: Library not found: could not resolve 'avfilter-9.dll', dependency of 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchaudio\\lib\\libtorchaudio_ffmpeg6.pyd'.
160760 WARNING: Library not found: could not resolve 'avformat-60.dll', dependency of 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchaudio\\lib\\libtorchaudio_ffmpeg6.pyd'.
160760 WARNING: Library not found: could not resolve 'avutil-57.dll', dependency of 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchaudio\\lib\\libtorchaudio_ffmpeg5.pyd'.
160762 WARNING: Library not found: could not resolve 'avformat-59.dll', dependency of 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchaudio\\lib\\libtorchaudio_ffmpeg5.pyd'.
160763 WARNING: Library not found: could not resolve 'avcodec-59.dll', dependency of 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchaudio\\lib\\libtorchaudio_ffmpeg5.pyd'.
160764 WARNING: Library not found: could not resolve 'avfilter-8.dll', dependency of 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchaudio\\lib\\libtorchaudio_ffmpeg5.pyd'.
160764 WARNING: Library not found: could not resolve 'avformat-58.dll', dependency of 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchaudio\\lib\\libtorchaudio_ffmpeg4.pyd'.
160766 WARNING: Library not found: could not resolve 'avcodec-58.dll', dependency of 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchaudio\\lib\\libtorchaudio_ffmpeg4.pyd'.
160766 WARNING: Library not found: could not resolve 'avutil-56.dll', dependency of 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchaudio\\lib\\libtorchaudio_ffmpeg4.pyd'.
160767 WARNING: Library not found: could not resolve 'avfilter-7.dll', dependency of 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchaudio\\lib\\libtorchaudio_ffmpeg4.pyd'.
160769 WARNING: Library not found: could not resolve 'avutil-58.dll', dependency of 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchaudio\\lib\\_torchaudio_ffmpeg6.pyd'.
160769 WARNING: Library not found: could not resolve 'avdevice-60.dll', dependency of 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchaudio\\lib\\_torchaudio_ffmpeg6.pyd'.
160770 WARNING: Library not found: could not resolve 'avfilter-9.dll', dependency of 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchaudio\\lib\\_torchaudio_ffmpeg6.pyd'.
160771 WARNING: Library not found: could not resolve 'avcodec-60.dll', dependency of 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchaudio\\lib\\_torchaudio_ffmpeg6.pyd'.
160772 WARNING: Library not found: could not resolve 'avformat-60.dll', dependency of 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchaudio\\lib\\_torchaudio_ffmpeg6.pyd'.
160772 WARNING: Library not found: could not resolve 'avformat-59.dll', dependency of 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchaudio\\lib\\_torchaudio_ffmpeg5.pyd'.
160773 WARNING: Library not found: could not resolve 'avdevice-59.dll', dependency of 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchaudio\\lib\\_torchaudio_ffmpeg5.pyd'.
160774 WARNING: Library not found: could not resolve 'avcodec-59.dll', dependency of 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchaudio\\lib\\_torchaudio_ffmpeg5.pyd'.
160774 WARNING: Library not found: could not resolve 'avutil-57.dll', dependency of 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchaudio\\lib\\_torchaudio_ffmpeg5.pyd'.
160775 WARNING: Library not found: could not resolve 'avfilter-8.dll', dependency of 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchaudio\\lib\\_torchaudio_ffmpeg5.pyd'.
160776 WARNING: Library not found: could not resolve 'avcodec-58.dll', dependency of 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchaudio\\lib\\_torchaudio_ffmpeg4.pyd'.
160776 WARNING: Library not found: could not resolve 'avutil-56.dll', dependency of 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchaudio\\lib\\_torchaudio_ffmpeg4.pyd'.
160777 WARNING: Library not found: could not resolve 'avformat-58.dll', dependency of 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchaudio\\lib\\_torchaudio_ffmpeg4.pyd'.
160778 WARNING: Library not found: could not resolve 'avdevice-58.dll', dependency of 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchaudio\\lib\\_torchaudio_ffmpeg4.pyd'.
160778 WARNING: Library not found: could not resolve 'avfilter-7.dll', dependency of 'D:\\PythonProjects\\FruitDetectv2\\.venv\\lib\\site-packages\\torchaudio\\lib\\_torchaudio_ffmpeg4.pyd'.
161165 INFO: Warnings written to D:\PythonProjects\FruitDetectv2\build\Detect\warn-Detect.txt
161708 INFO: Graph cross-reference written to D:\PythonProjects\FruitDetectv2\build\Detect\xref-Detect.html
161943 INFO: checking PYZ
161943 INFO: Building PYZ because PYZ-00.toc is non existent
161944 INFO: Building PYZ (ZlibArchive) D:\PythonProjects\FruitDetectv2\build\Detect\PYZ-00.pyz
166649 INFO: Building PYZ (ZlibArchive) D:\PythonProjects\FruitDetectv2\build\Detect\PYZ-00.pyz completed successfully.
166816 INFO: checking PKG
166817 INFO: Building PKG because PKG-00.toc is non existent
166817 INFO: Building PKG (CArchive) Detect.pkg
595554 INFO: Building PKG (CArchive) Detect.pkg completed successfully.
595630 INFO: Bootloader D:\PythonProjects\FruitDetectv2\.venv\lib\site-packages\PyInstaller\bootloader\Windows-64bit-intel\runw.exe
595630 INFO: checking EXE
595630 INFO: Building EXE because EXE-00.toc is non existent
595630 INFO: Building EXE from EXE-00.toc
595631 INFO: Copying bootloader EXE to D:\PythonProjects\FruitDetectv2\dist\Detect.exe
595634 INFO: Copying icon to EXE
595636 INFO: Copying 0 resources to EXE
595636 INFO: Embedding manifest in EXE
595637 INFO: Appending PKG archive to EXE
598075 INFO: Fixing EXE headers
608638 INFO: Building EXE from EXE-00.toc completed successfully.

这是我正在尝试构建的代码

# Import Libraries
from ultralytics import YOLO
import cv2
import math
import cvzone
import numpy as np
import tkinter as tk
from tkinter import filedialog
from tkinter import *
from PIL import Image,ImageTk
if __name__ == '__main__':

    root = tk.Tk()
    root.geometry("1920x1080")
    root.resizable(width=True, height=True)
    root.title("Fruit Detection")

    main_frame = tk.Frame(root, bg='#020f12')
    main_frame.pack(fill=tk.BOTH, expand=True)
    main_frame.columnconfigure(0, weight=1)
    main_frame.columnconfigure(1, weight=5)
    main_frame.rowconfigure(0, weight=1)
    main_frame.rowconfigure(1, weight=1)
    main_frame.rowconfigure(2, weight=1)
    main_frame.rowconfigure(3, weight=1)


    def task(button):

        match button:
            case 'button1':
                #root.image = filedialog.askopenfilename(initialdir="/desktop", title="Select image to detect")
                cap = cv2.imread("PXL_20240117_233550643.MV.jpg")
                model = YOLO("best.pt")

                classNames = ['Orange', 'Orange', 'Pomegranate', 'Pomegranate', 'apple', 'apple', 'banana', 'banana',
                              'fruits', 'guava', 'guava', 'guava', 'lime', 'lime']
                while True:
                    success, img = cap.read()
                    results = model(img, stream=True)
                    for r in results:  # data from detect
                        boxes = r.boxes
                        for box in boxes:  # box values
                            x1, y1, x2, y2 = box.xyxy[0]  # detection
                            x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)

                            conf = math.ceil((box.conf[0] * 100)) / 100  # confidence
                            print(conf)

                            if conf > 0.75:
                                cv2.rectangle(img, (x1, y1), (x2, y2), (255, 255, 0), 3)  # image, color, thickness
                                cls = int(box.cls[0])  # find what the object is
                                cvzone.putTextRect(img, f'{classNames[cls]}{conf}', (max(0, x1), max(40, y1)), scale=1,
                                                   thickness=1)
                        #img = cv2.resize(img,(1280, 720))
                        img = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
                        img = ImageTk.PhotoImage(Image.fromarray(img))
                        camera['image'] = img
                        root.update()
                        #cv2.imshow("DetectVideo", img)
                        k = cv2.waitKey(1)
                        print(k)
                    if k == 27:  # close on ESC key
                        cv2.destroyAllWindows()
                        break

            case 'button2':
                root.video = filedialog.askopenfilename(initialdir="/desktop", title="Select video to detect")
                cap = cv2.VideoCapture(root.video)

                model = YOLO('best.pt')

                classNames = ['Orange', 'Orange', 'Pomegranate', 'Pomegranate', 'apple', 'apple', 'banana', 'banana',
                              'fruits', 'guava', 'guava', 'guava', 'lime', 'lime']

                while True:
                    success, img = cap.read()
                    results = model(img, stream=True)
                    for r in results:  # data from detect
                        boxes = r.boxes
                        for box in boxes:  # box values
                            x1, y1, x2, y2 = box.xyxy[0]  # detection
                            x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)

                            conf = math.ceil((box.conf[0] * 100)) / 100  # confidence
                            print(conf)

                            if conf > 0.75:
                                cv2.rectangle(img, (x1, y1), (x2, y2), (255, 255, 0), 3)  # image, color, thickness
                                cls = int(box.cls[0])  # find what the object is
                                cvzone.putTextRect(img, f'{classNames[cls]}{conf}', (max(0, x1), max(40, y1)), scale=1, font=cv2.FONT_HERSHEY_COMPLEX_SMALL,
                                                   thickness=1)
                        #img = cv2.resize(img,(1280, 720))
                        img = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
                        img = ImageTk.PhotoImage(Image.fromarray(img))
                        camera['image'] = img
                        root.update()
                        #cv2.imshow("DetectVideo", img)
                        '''
                        k = cv2.waitKey(1)
                        print(k)
                    if k == 27:  # close on ESC key
                        cv2.destroyAllWindows()
                        break
                        '''

            case 'button3':
                cap = cv2.VideoCapture(1)
                cap.set(3, 1920)  # width
                cap.set(4, 1080)  # height

                model = YOLO('best.pt')

                classNames = ['Orange', 'Orange', 'Pomegranate', 'Pomegranate', 'apple', 'apple', 'banana', 'banana',
                              'fruits',
                              'guaba', 'guava', 'guava', 'lime', 'lime']

                while True:
                    success, img = cap.read()
                    results = model(img, stream=True)

                    for r in results:  # data from detect
                        boxes = r.boxes
                        for box in boxes:  # box values
                            x1, y1, x2, y2 = box.xyxy[0]  # detection
                            x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)

                            conf = math.ceil((box.conf[0] * 100)) / 100
                            print(conf)

                            if conf > 0.88:
                                cv2.rectangle(img, (x1, y1), (x2, y2), (255, 255, 0), 3)  # image, color, thickness
                                cls = int(box.cls[0])  # find what the object is
                                cvzone.putTextRect(img, f'{classNames[cls]}{conf}', (max(0, x1), max(40, y1)), scale=4,
                                                   thickness=3)
                        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
                        img = ImageTk.PhotoImage(Image.fromarray(img))
                        camera['image'] = img
                        root.update()
                        #cv2.imshow("FruitWebcam", img)
                        k = cv2.waitKey(1)
                        print(k)
                    if k == 27:  # close on ESC key
                        cv2.destroyAllWindows()
                        break

    frame = LabelFrame(main_frame,width=1920,height=1080,bg='black')
    frame.grid(column=1,rowspan=3)
    camera = Label(frame,bg='black')
    camera.pack()
    #camera = Label(main_frame,width=1280,height=720)
    #camera.grid(column=1,rowspan=3)

    # Define a function to stop the loop
    def on_stop():
        global running
        running = False

    button4 = tk.Button(main_frame, text="Start", command=on_stop)
    button4.grid(column=0,row=4)

    button1 = tk.Button(
        main_frame,
        background='#05d7ff',
        foreground='BLACK',
        activebackground='TEAL',
        activeforeground='BLUE',
        highlightthickness=2,
        highlightbackground='GREY',
        highlightcolor='WHITE',
        width=13,
        height=2,
        text='Image',
        font=('Arial', 16, 'bold'),
        command=lambda: task('button1')
    )
    button1.grid(column=0, row=0)


    button2 = tk.Button(
        main_frame,
        background='#05d7ff',
        foreground='BLACK',
        activebackground='TEAL',
        activeforeground='BLUE',
        highlightthickness=2,
        highlightbackground='GREY',
        highlightcolor='WHITE',
        width=13,
        height=2,
        text='Video',
        font=('Arial', 16, 'bold'),
        command=lambda: task('button2')
    )
    button2.grid(column=0, row=1)

    button3 = tk.Button(
        main_frame,
        background='#05d7ff',
        foreground='BLACK',
        activebackground='TEAL',
        activeforeground='BLUE',
        highlightthickness=2,
        highlightbackground='GREY',
        highlightcolor='WHITE',
        width=13,
        height=2,
        text='Webcam',
        font=('Arial', 16, 'bold'),
        command=lambda: task('button3')
    )
    button3.grid(column=0, row=2)

    root.mainloop()

从其他论坛,我尝试使用参数

--noupx
--windowed
,没有我包含的两个参数,但得到相同的错误

python python-3.x opencv pyinstaller
1个回答
0
投票

缺少像

avcodec-60.dll
avutil-58.dll
这样的库(
torchaudio
需要)。因此,您需要安装
ffmpeg
,如果已经安装,您可以使用
.spec
文件来指示dll位置

a = Analysis(['the_python_script.py'],
             ...
             binaries=[('path/to/ffmpeg/dlls/*.dll', '.')],
             ...)
© www.soinside.com 2019 - 2024. All rights reserved.