Answer a question

I've tried commenting out as much as possible to eliminate any external problem. I try running it using python manage.py runserver and get the error:

File "app\manage.py", line 3, in <module>
  from .app import app
ImportError: attempted relative import with no known parent package

manage.py and app.py are in the same directory. Line 3 is the app import line.

manage.py

from flask_script import Manager

from .app import app

manager = Manager(app)

if __name__ == '__main__':
    manager.run()

app.py

from flask import Flask

app = Flask(__name__, static_folder="./static/dist", template_folder="./static")

If it means anything I've also run Inspect Code inside PyCharm and get no errors.

Answers

When you run python something.py, that file isn't considered to be part of a package --- only modules that are imported or are run with python -m are.

In this case the solution is probably to replace the line that tries to import your app.py with

from app.app import app

or

from app import app

... depending on what's in your sys.path and where your project folder is placed.

Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐