Python flask.cli.NoAppException:无法导入“flaskr.flaskr”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50574293/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
flask.cli.NoAppException: Could not import "flaskr.flaskr"
提问by DavidGodwin
I'm working through: http://flask.pocoo.org/docs/1.0/tutorial/
我正在解决:http: //flask.pocoo.org/docs/1.0/tutorial/
I've written __init__.py
(code here: http://codepad.org/4FGIE901) in a /flaskr/ directory, set up a virtual environment called 'venv' and installed Flask.
我已经在 /flaskr/ 目录中编写了__init__.py
(代码在这里:http: //codepad.org/4FGIE901),设置了一个名为“venv”的虚拟环境并安装了 Flask。
I then ran these commands — on the command line, in the flaskr directory?– as 'Run the application' advises: (export FLASK_APP=flaskr
, export FLASK_ENV=development
, flask run
)
然后我运行了这些命令——在命令行上,在flaskr目录中?——正如“运行应用程序”所建议的那样:( export FLASK_APP=flaskr
, export FLASK_ENV=development
, flask run
)
What I should see is Hello, World!
我应该看到的是 Hello, World!
Instead, I'm presented with the following errors:
相反,我遇到了以下错误:
Traceback (most recent call last):
File "/Users/David/Desktop/flaskr/venv/lib/python3.6/site-packages/flask/cli.py", line 330, in __call__
rv = self._load_unlocked()
File "/Users/David/Desktop/flaskr/venv/lib/python3.6/site-packages/flask/cli.py", line 317, in _load_unlocked
self._app = rv = self.loader()
File "/Users/David/Desktop/flaskr/venv/lib/python3.6/site-packages/flask/cli.py", line 372, in load_app
app = locate_app(self, import_name, name)
File "/Users/David/Desktop/flaskr/venv/lib/python3.6/site-packages/flask/cli.py", line 246, in locate_app
'Could not import "{name}".'.format(name=module_name)
flask.cli.NoAppException: Could not import "flaskr.flaskr".
Simply, I'm not sure how I should respond to or work upon fixing an error like this. Perhaps I have a mismatch in what I have installed in the venv and what this particular project requires?
简单地说,我不确定我应该如何响应或修复这样的错误。也许我在 venv 中安装的内容与此特定项目的要求不匹配?
Like this person: Could not Import Pandas: TypeError
喜欢这个人:无法导入熊猫:TypeError
Flask:
烧瓶:
/Users/David/Desktop/flaskr/venv/bin/Flask
- Version: 1.0.2
/Users/David/Desktop/flaskr/venv/bin/Flask
- 版本:1.0.2
Pip:
点:
from /Users/David/Desktop/flaskr/venv/lib/python3.6/site-packages (python 3.6)
- Version: 9.0.1
from /Users/David/Desktop/flaskr/venv/lib/python3.6/site-packages (python 3.6)
- 版本:9.0.1
Python:
Python:
/Users/David/Desktop/flaskr/venv/bin/python
- Version: 3.6.0
/Users/David/Desktop/flaskr/venv/bin/python
- 版本:3.6.0
回答by Garden Li
I think you are in the wrong folder. You probably did:
我认为你在错误的文件夹中。你可能做了:
cd flask_tutorial/flaskr
You need to go up to the tutorial folder:
您需要转到教程文件夹:
cd ..
You should flask run
in the flask_tutorial
folder rather than flask_tutorial/flaskr
because you want to import flaskr
from that folder, not flaskr/flaskr
(which doesn't exist).
您应该flask run
在flask_tutorial
文件夹中,而不是flask_tutorial/flaskr
因为您想flaskr
从该文件夹导入,而不是flaskr/flaskr
(不存在)。
回答by Mega sharif
Those running flask for the first time ..This works well for windows
那些第一次运行烧瓶的人..这适用于 Windows
find the location of your folder use cmd please 'mine is cd /users/hp/Desktop'
使用 cmd 找到您文件夹的位置,请“我的是 cd /users/hp/Desktop”
cd /users/hp/Desktop>set FLASK_APP=hello.py -->file name
cd /users/hp/Desktop>set FLASK_ENV=development
cd /users/hp/Desktop>flask run
cd /users/hp/Desktop>set FLASK_APP=hello.py -->file name
cd /users/hp/Desktop>set FLASK_ENV=development
cd /users/hp/Desktop>flask run