Reputation: 43
I am working on python3 learn the hard way book exercise 52. while running on my nosetests I am getting import error.
ERROR: Failure: ImportError (cannot import name 'escape' from 'flask' (/usr/local/lib/python3.10/dist-packages/flask/__init__.py))
File "/home/dhivya/projects/gothonweb/tests/app_tests.py", line 2, in <module> from app import app
File "/home/dhivya/projects/gothonweb/app.py", line 1, in <module> from flask import Flask, session, redirect, url_for, escape, request
ImportError: None
My flask installed version and location Name: Flask Version: 3.0.2 Summary: A simple framework for building complex web applications. Home-page: Author: Author-email: License: Location: /usr/local/lib/python3.10/dist-packages Requires: blinker, click, itsdangerous, Jinja2, Werkzeug Required-by:
I have tried uninstall and reinstall the flask. I think my flask installed location and expected location is different (there is no init.py file) but not sure.can someone help me to resolve this error?
Upvotes: 4
Views: 2298
Reputation: 385
The error you're actually getting is cannot import name 'escape' from 'flask'
. There's no issue with flask installation location and the name __init__.py
has nothing to do with the error and is a naming convention for python to recognize packages that can be imported and not specific to flask
Version 2.3.0
Released 2023-04-25
Importing escape and Markup from flask is deprecated. Import them directly from markupsafe instead. #4996
You're using version 3.0.2 > 2.3.0
So use from markupsafe import escape
instead of from flask import escape
Upvotes: 10