在安装所有要求并通过以下方式启动应用程序后,我从 git 克隆了一个烧瓶应用程序
$蟒蛇开始.py
我收到以下错误
Traceback (most recent call last):
File "start.py", line 6, in <module>
app = create_app("local")
File "C:\Jahangeer\qurbcode\api\app\__init__.py", line 66, in create_app
from app.api_1_0 import apibp as api_1_0, api_spec as api_1_0_spec
File "C:\Jahangeer\qurbcode\api\app\api_1_0\__init__.py", line 78, in <module>
ModuleImport.importModulesFromPath(os.path.dirname(os.path.realpath(__file__)), __name__)
File "C:\Jahangeer\qurbcode\api\app\helpers\module_import.py", line 16, in importModulesFromPath
importlib.import_module("." + module, package)
File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
ImportError: Import by filename is not supported.
Start.py 有以下代码
import os
from app import create_app
app = create_app("local")
if __name__ == '__main__':
app.run(host= '0.0.0.0', threaded=True)
并且在上面错误中提到的第 66 行的init .py 内部具有以下内容
# Setup api/1.0 blueprint
from .api_1_0 import apibp as api_1_0, api_spec as api_1_0_spec
from .admin import admin_bp as admin
app.register_blueprint(api_1_0, url_prefix='/api/1.0')
这是应用程序结构
api
->admin_app
->app
->admin
->api_1_0
->__init__.py
->start.py
->manage.py
我的 api\app\helpers\module_import.py 有以下代码:
import glob
import importlib
class ModuleImport:
@staticmethod
def importModulesFromPath(dir_path, package, import_init = False):
files = glob.glob(dir_path + "/*.py")
for file in files:
module = file.replace(dir_path, "").replace("/", "").replace(".py", "")
if module == "__init__" and not import_init:
continue
importlib.import_module("." + module, package)
我的 api\app\api_1_0__init__.py 有以下代码:在第 78 行
ModuleImport.importModulesFromPath(os.path.dirname(os.path.realpath(__file__)), __name__)