Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

execute hello world with flask "ImportError: No module named flask"

Tags:

I'm trying to use flask and python. I did a simple file named hello.py. tHis file contains this code:

from flask import Flask app = Flask(__name__)   @app.route("/") def main():     return "Welcome!"  if __name__ == "__main__":     app.run() 

This is a simple hello world with flask. I want to execute it but actually, I have a problem. In the terminal, I typed python hello.py and I get this error:

File "hello.py", line 1, in <module> from flask import Flask ImportError: No module named flask 

Even that I installed flask globally. I understand that this is a basic question, but I'm stuck?

like image 549
Lindages Avatar asked Jan 14 '16 09:01

Lindages


People also ask

How do you run a Flask?

To run the app outside of the VS Code debugger, use the following steps from a terminal: Set an environment variable for FLASK_APP . On Linux and macOS, use export set FLASK_APP=webapp ; on Windows use set FLASK_APP=webapp . Navigate into the hello_app folder, then launch the program using python -m flask run .

What is Flask module in Python?

Flask is a web framework, it's a Python module that lets you develop web applications easily. It's has a small and easy-to-extend core: it's a microframework that doesn't include an ORM (Object Relational Manager) or such features. It does have many cool features like url routing, template engine.


1 Answers

You don't have installed flask

Linux:

Install flask as global package:

sudo pip install flask 

Install in virtualenv

virtualenv venv source venv pip install flask 

Install system package

  • debian, ubuntu

    apt-get install python-flask 
  • arch

    pacman -S python-flask 
  • fedora

    yum install python-flask 

Install via Anaconda

conda install flask 

Windows:

python -m pip install flask 
like image 58
Tomasz Jakub Rup Avatar answered Sep 21 '22 17:09

Tomasz Jakub Rup