导入错误:无法从“torch._dynamo.utils”导入名称“NP_SUPPORTED_MODULES”

问题描述 投票:0回答:1
try:
    import os
    from bs4 import BeautifulSoup as bs
    import xlsxwriter
    import sys,traceback
    import time,threading
    import PySimpleGUI as sg
    import requests
    import easyocr
    import certifi
    from datetime import datetime
    from pymongo import MongoClient
    from bson.objectid import ObjectId
except:
    sys.stderr = open('../error.log', 'a+',encoding='utf-8')
    traceback.print_exc()
    sys.stderr.close()

reader = easyocr.Reader(['en']) # this needs to run only once to load the model into memory

回溯

(most recent call last):
  File "D:\Developing\W.S-PROJECT\osos.adanaorganize.org.tr\osos_adanaorganize_scraper.py", line 9, in <module>
    import easyocr
  File "D:\Developing\W.S-PROJECT\osos.adanaorganize.org.tr\env\lib\site-packages\easyocr\__init__.py", line 1, in <module>
    from .easyocr import Reader
  File "D:\Developing\W.S-PROJECT\osos.adanaorganize.org.tr\env\lib\site-packages\easyocr\easyocr.py", line 3, in <module>
    from .recognition import get_recognizer, get_text
  File "D:\Developing\W.S-PROJECT\osos.adanaorganize.org.tr\env\lib\site-packages\easyocr\recognition.py", line 6, in <module>
    import torchvision.transforms as transforms
  File "D:\Developing\W.S-PROJECT\osos.adanaorganize.org.tr\env\lib\site-packages\torchvision\__init__.py", line 6, in <module>
    from torchvision import _meta_registrations, datasets, io, models, ops, transforms, utils
  File "D:\Developing\W.S-PROJECT\osos.adanaorganize.org.tr\osos-scraper-_win_application\lib\torchvision\models\__init__.py", line 2, in <module>
    from .convnext import *
  File "D:\Developing\W.S-PROJECT\osos.adanaorganize.org.tr\osos-scraper-_win_application\lib\torchvision\models\convnext.py", line 8, in <module>
    from ..ops.misc import Conv2dNormActivation, Permute
  File "D:\Developing\W.S-PROJECT\osos.adanaorganize.org.tr\env\lib\site-packages\torchvision\ops\__init__.py", line 23, in <module>
    from .poolers import MultiScaleRoIAlign
  File "D:\Developing\W.S-PROJECT\osos.adanaorganize.org.tr\env\lib\site-packages\torchvision\ops\poolers.py", line 10, in <module>
    from .roi_align import roi_align
  File "D:\Developing\W.S-PROJECT\osos.adanaorganize.org.tr\env\lib\site-packages\torchvision\ops\roi_align.py", line 4, in <module>
    import torch._dynamo
  File "D:\Developing\W.S-PROJECT\osos.adanaorganize.org.tr\env\lib\site-packages\torch\_dynamo\__init__.py", line 2, in <module>
    from . import allowed_functions, convert_frame, eval_frame, resume_execution
  File "D:\Developing\W.S-PROJECT\osos.adanaorganize.org.tr\env\lib\site-packages\torch\_dynamo\allowed_functions.py", line 30, in <module>
    from .utils import hashable, is_safe_constant, NP_SUPPORTED_MODULES
ImportError: cannot import name 'NP_SUPPORTED_MODULES' from 'torch._dynamo.utils' (D:\Developing\W.S-PROJECT\osos.adanaorganize.org.tr\osos-scraper-_win_application\lib\torch\_dynamo\utils.pyc)

当我在 vs code 中运行脚本时,它可以正常工作。 但是当我使用 cx_freeze 创建 exe 时,它已成功创建。 我运行 exe 后出现此错误。

python pytorch cx-freeze easyocr
1个回答
0
投票

我也有同样的问题。 并通过将

"torch"
添加到我的 setup.py 文件中的包来解决它,并且您还需要制作
base='console'

我的旧代码(不起作用):

from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need
# fine tuning.
build_options = {'packages': [], 'excludes': [], 'include_files': ['settings.ini','design.ui']}

import sys
base = 'Win32GUI' if sys.platform=='win32' else None

executables = [
    Executable('ozvuchator.py', base=base, target_name = 'Ozvuchator')
]

setup(name='test',
      version = '1',
      description = 'no',
      options = {'build_exe': build_options},
      executables = executables)

我的固定代码:

from cx_Freeze import setup, Executable


build_options = {'packages': ["torch", "PySide6"], 'excludes': [], 'include_files': ['settings.ini','design.ui']}

base = 'console'

executables = [
    Executable('ozvuchator.py', base=base)
]

setup(name='test',
      version = '1',
      description = 'no',
      options = {'build_exe': build_options},
      executables = executables)
© www.soinside.com 2019 - 2024. All rights reserved.