简体   繁体   English

无法导入.py 文件,没有名为“文件名”的模块错误

[英]Can't import .py file, no module named 'filename' error

I'm trying to import a.py file into another.py file and I get the error No module named 'filename'我正在尝试将 a.py 文件导入到 another.py 文件中,但出现错误 No module named 'filename'

Here's my directory:这是我的目录:

(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

I'm trying to use apiDnd.py in routes.py我正在尝试在 routes.py 中使用 apiDnd.py

My __init__.py file:我的__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

My routes.py file:我的routes.py文件:

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

Everything works fine without the import apiDnd line and that's where the error is.没有import apiDnd行,一切正常,这就是错误所在。

Replace import apiDnd in routes.py with from. import apiDnd将 routes.py 中的import apiDnd routes.pyfrom. import apiDnd from. import apiDnd . from. import apiDnd

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM