【问题标题】:Can't import .py file, no module named 'filename' error无法导入 .py 文件,没有名为“文件名”的模块错误
【发布时间】:2020-04-21 23:10:17
【问题描述】:

我正在尝试将 .py 文件导入另一个 .py 文件,但出现错误 No module named 'filename'

这是我的目录:

(local files)/app/__init__.py
(local files)/app/routes.py
(local files)/app/errors.py
(local files)/app/forms.py
(local files)/app/apiDnd.py

我正在尝试在 routes.py 中使用 apiDnd.py

我的__init__.py 文件:

from flask import Flask
from config import Config

app = Flask(__name__)
app._static_folder = '../static'
app.config.from_object(Config)

from app import routes, errors, apiDnd

我的routes.py 文件:

from flask import render_template, flash, redirect, url_for, jsonify, request, json
from app import app
import apiDnd

没有import apiDnd 行一切正常,这就是错误所在。

【问题讨论】:

    标签: python flask python-import


    【解决方案1】:

    routes.py 中的import apiDnd 替换为from . import apiDnd

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-19
      • 2018-01-06
      • 2012-12-16
      • 1970-01-01
      • 2013-10-22
      • 2013-05-05
      • 2018-01-15
      相关资源
      最近更新 更多