from flask import Flask
app = Flask(__name__)
@app.route("/")
def index():
return "This is the homepage"
if __name__ == "__main__":
app.run(debug=True)
在IDLE中运行此烧瓶程序时,收到以下错误消息:
Traceback (most recent call last):
File "/Users/Arnav/Documents/flaskpractice.py", line 1, in <module>
from flask import Flask
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/flask/__init__.py", line 21, in <module>
from .app import Flask, Request, Response
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/flask/app.py", line 19, in <module>
from werkzeug.routing import Map, Rule, RequestRedirect, BuildError
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/werkzeug/routing.py", line 103, in <module>
from pprint import pformat
ImportError: cannot import name pformat
我正在使用Python 2.7.13并且我安装了烧瓶。我试过谷歌搜索错误,但没有得到修复。请帮帮我
答案 0 :(得分:0)
为了从virtualenv运行一个烧瓶应用程序,您可以创建一个文件run_idle.py
文件,并从与烧瓶应用程序相同的目录中启动它。将其放入run_idle.py
并使用python run_idle.py
:
from idlelib.PyShell import main
if __name__ == '__main__':
main()
它将从virtualenv运行IDLE,以便它将看到安装了该烧瓶。请注意,您需要在使用以下命令运行IDLE之前激活virtualenv:
. env/bin/activate