'Flask fails with "Error: While importing 'X', an ImportError was raised", but does not display the error. How to find the source of the error?
When starting a Flask app with:
$ flask run
I received the error:
Error: While importing 'wsgi', an ImportError was raised. Usage: flask [OPTIONS] COMMAND [ARGS]...` ...
However, there is no stack trace or other information provided. What is the best way to get the ImportError stack trace?
Solution 1:[1]
This error can be caused if Flask is unable to import any libraries(in my case it was Flask_restful)
This is the workaround I found to find the missing libraries:-
I found which library was missing by just running the Flask App file (wsgi.py) directly with python
python wsgi.py
which gave an Importerror listing the missing libraries
after finding the missing libraries, simply install libraries using pip, for me Flask_restful was missing so I installed Flask_restful . After installing missing libraries simply run the flask app using
flask run
Solution 2:[2]
The only thing that I would add to Christopher Peisert's answer is the option that gave me the error messages that I was searching for:
(venv) ~/example_flask_app/$ python
>>> import app
Or in my case
>>> import microblog
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Vishal Raju |
| Solution 2 | Alexx Roche |
