简体   繁体   中英

Getting ImportError: cannot import name pformat when running Flask App. I am using Python 2.7.13 and have flask installed

from flask import Flask

app = Flask(__name__)

@app.route("/")
def index():
    return "This is the homepage"

if __name__ == "__main__":
    app.run(debug=True)

While running this flask program in IDLE, I get this error message:

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

I am using Python 2.7.13 and I have flask installed. I tried googling the error but didn't get a fix. Please help me

In order to run a flask app from virtualenv you can create a file run_idle.py file and launch it from the same directory as your flask app. Put this into run_idle.py and run it using python run_idle.py :

from idlelib.PyShell import main

if __name__ == '__main__':
    main()

It will run IDLE from the virtualenv so that it will see that flask is installed. Note that you need to activate virtualenv before running IDLE using:

. env/bin/activate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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