Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NameError: name 'flask' is not defined

Tags:

python

flask

I am facing problem while running this line of code in the terminal:

$ sudo python app.py 

And the Traceback is :

Traceback (most recent call last):

  File "app.py", line 7, in <module>

   APP = flask.Flask(__name__)

NameError: name 'flask' is not defined

sudo pip install flask

Requirement already satisfied (use --upgrade to upgrade): flask in 

/usr/local/lib/python2.7/dist-packages

Requirement already satisfied (use --upgrade to upgrade): Werkzeug>=0.7 in 

/usr/local/lib/python2.7/dist-packages (from flask)

Requirement already satisfied (use --upgrade to upgrade): Jinja2>=2.4 in 

/usr/local/lib/python2.7/dist-packages (from flask)

Requirement already satisfied (use --upgrade to upgrade): 

itsdangerous>=0.21 in /usr/local/lib/python2.7/dist-packages (from flask)

Requirement already satisfied (use --upgrade to upgrade): markupsafe in 

/usr/lib/python2.7/dist-packages (from Jinja2>=2.4->flask)

Cleaning up...

Any help would be appreciated.

like image 985
kaio Avatar asked Apr 05 '15 13:04

kaio


People also ask

How do I fix NameError is not defined in Python?

The Python "NameError: function is not defined" occurs when we try to call a function that is not declared or before it is declared. To solve the error, make sure you haven't misspelled the function's name and call it after it has been declared.

Is not defined flask?

The error name 'flask' is not defined comes when you are not properly using the flask module. You are importing a flask module instead of flask. Flask() you are using a flask module.

How do I solve NameError?

The Python "NameError: name is not defined" occurs when we try to access a variable or function that is not defined or before it is defined. To solve the error, make sure you haven't misspelled the variable's name and access it after it has been declared.

What is __ name __ In flask?

__name__ is just a convenient way to get the import name of the place the app is defined. Flask uses the import name to know where to look up resources, templates, static files, instance folder, etc.


1 Answers

if flask is not installed:

pip install flask

then

import flask
like image 192
Hackaholic Avatar answered Sep 17 '22 03:09

Hackaholic