gpt4 book ai didi

python-3.x - 无法为 API 设置 DEFAULT_PARSERS 导入 flask_api.parsers.JSONParser

转载 作者:行者123 更新时间:2023-12-03 16:13:07 24 4
gpt4 key购买 nike

我有一个包含多个脚本、模板和静态文件夹的 flask 项目。
我正在使用多个 flask 模块,如 flask_pymongo、flask_cors 和 flask_api。
我正在尝试使用 PyInstaller 构建 .EXE 格式的可执行 Windows 程序。

我运行以下命令

 `python -m PyInstaller -F --add-data "templates;templates" --add-data "static;static"`

它构建成功。
62 INFO: PyInstaller: 3.5
62 INFO: Python: 3.6.0
62 INFO: Platform: Windows-8.1-6.3.9600-SP0
64 INFO: wrote C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\nobina\__init__.spec
65 INFO: UPX is not available.
66 INFO: Extending PYTHONPATH with paths
['C:\\Users\\mohammadreza\\PycharmProjects\\nobina\\nobina_exe',
'C:\\Users\\mohammadreza\\PycharmProjects\\nobina\\nobina_exe\\nobina']
66 INFO: checking Analysis
119 INFO: Appending 'datas' from .spec
123 INFO: checking PYZ
152 INFO: checking PKG
158 INFO: Building because toc changed
159 INFO: Building PKG (CArchive) PKG-00.pkg
2676 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
2711 INFO: Bootloader C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
2711 INFO: checking EXE
2719 INFO: Building because toc changed
2719 INFO: Building EXE from EXE-00.toc
2720 INFO: Appending archive to EXE C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\nobina\dist\__init__.exe
3310 INFO: Building EXE from EXE-00.toc completed successfully.

但是当我尝试在 dist 文件夹中运行我的程序时,我收到以下错误:
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

C:\Users\mohammadreza>cd C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe
\nobina\dist

C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\nobina\dist>__init__.exe

Traceback (most recent call last):
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\flask_api\settings.py", line 25, in import_from_string
module = importlib.import_module(module_path)
File "C:\Users\mohammadreza\AppData\Local\Programs\Python\Python36\lib\importl
ib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 948, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'flask_api.parsers'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\nobina\__init__.
py", line 22, in <module>
from nobina.installation import install
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\nobina\__init__.
py", line 22, in <module>
from nobina.installation import install
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\nobina\installat
ion.py", line 3, in <module>
from nobina.Models.Admin import Admin
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\nobina\Models\Ad
min.py", line 1, in <module>
from nobina.Models.Base import BaseModel, AggregateQuery
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\nobina\Models\Ba
se.py", line 1, in <module>
from nobina.utility import load_class, dump_class
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\nobina\utility.p
y", line 2, in <module>
from flask_api import status
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\flask_api\__init__.py", line 1, in <module>
from flask_api.app import FlaskAPI
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\flask_api\app.py", line 6, in <module>
from flask_api.request import APIRequest
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\flask_api\request.py", line 13, in <module>
class APIRequest(Request):
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\flask_api\request.py", line 14, in APIRequest
parser_classes = default_settings.DEFAULT_PARSERS
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\flask_api\settings.py", line 45, in DEFAULT_PARSERS
return perform_imports(val, 'DEFAULT_PARSERS')
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\flask_api\settings.py", line 13, in perform_imports
return [perform_imports(item, setting_name) for item in val]
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\flask_api\settings.py", line 13, in <listcomp>
return [perform_imports(item, setting_name) for item in val]
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\flask_api\settings.py", line 11, in perform_imports
return import_from_string(val, setting_name)
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\flask_api\settings.py", line 30, in import_from_string
raise ImportError(msg)
ImportError: Could not import 'flask_api.parsers.JSONParser' for API setting 'DE
FAULT_PARSERS'. No module named 'flask_api.parsers'.
[6808] Failed to execute script __init__

我尝试将 flask-api 降级到 v1.0,但也没有成功。
任何帮助将不胜感激。

最佳答案

我添加了 --hidden-import=flask_api.parsers & --hidden-import=flask_api.renderers它有效

关于python-3.x - 无法为 API 设置 DEFAULT_PARSERS 导入 flask_api.parsers.JSONParser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57129382/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com