Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

315
Visualizações
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?

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Import the Flask app at the Python interpreter prompt

To see the ImportError stack trace, open a Python interpreter prompt and import the module that loads the Flask app (usually app.py or wsgi.py). If applicable, be sure that your virtual environment is activated.

$ python
>>> from my_app_folder import app

Set the FLASK_APP environment variable

If you can import the Flask app module using the Python interpreter without error, try setting the FLASK_APP environment variable to point to the Flask app module.

$ FLASK_APP='my_app_folder/app' FLASK_ENV=development flask run
over 4 years ago · Santiago Trujillo Relatório

0

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
over 4 years ago · Santiago Trujillo Relatório

0

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
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda