Im using window 10, I did the command pip install flask but I kept getting a ImportError: cannot import name 'Flask'. When I worked with flask couple months back it was running fine. Came back to run my old programs today and i get this error? I was just trying to run a simple html website.
from flask import Flask, render_template
from flask import request
app = Flask(__name__)
app.static_folder = 'static'
#app.route('/')
def index():
return render_template('index.html')
if __name__=='__main__':
app.run(debug = True)
Also before this error I had No module named 'Flask' so I did(found this in other stackoverflow post):
1. virtualenv
2. pip install flask (getting output that requirements are already satisfied)
3. Then I just try to run my flask which is called i.py and I get cannot import name 'Flask'. Went through many solutions on here still no idea how to fix it.
Basically i had 2 versions of python 3.6 and 3.5.2 when I deleted 3.6 its working fine.
Related
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?
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
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
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
I am a beginner with the python programming.
I have python 3 installed in my local system.
I coding along as part of a tutorial video and as part of the tutorial, i have created a virtual environment and created an app.py file with the below content.
from flask import Flask
app = Flask(__name__)
#app.route("/")
def index():
return "Hello, World!"
if __name__ == "__main__":
app.run()
I have installed all the dependencies like flask and pytest in the virtual environment as per the tutorial using gitbash.But when i run the command python3 app.py in gitbash i get the below error message
File "C:\path\Python\python-github-actions-example\src\app.py", line 1, in <module>
from flask import Flask
ModuleNotFoundError: No module named 'flask'
(myvenv)
I checked the python version and it is python 3.9.7
If i run python app.py i get the output.
Why is it not running even though correct version is installed
Any idea why ?
Try to delete the venv or make a new one.
Then create a new venv like this:
virtualenv flask
Go to the flask directory
: cd flask
Activate it: scripts\activate
You should see (flask) on the left of the command line.
Install flask again: pip install flask
Run your file again.
Some times you need to change/select de versiĆ³n/env if you after installed. like it if work for you.
After you do what #kmogi says in their post above, start the app with python not python3.
I typed "from flask import flask" in my python shell. it is now showing import error "cannot import name flask from flask".
It is just title case needs to be Capital letter. try this
from flask import Flask
Try installing Flask with:
pip install Flask
trying to use the VM as a server to host some python code but it has a problem with the files import of 'firebase'
Output: ImportError: No module named firebase
Has anyone had this or anything like this before?
The file which I'm trying run the app from is (serveme.py):
from flask import Flask, request, render_template
from firebase import firebase
import json
import requests
import os.path
firebase = firebase.FirebaseApplication('https://***********.firebaseio.com/')
app = Flask(__name__)
#app.route('/')
def index():
return 'Method was %s' % request.method
#app.route('/firetest', methods=['GET', 'POST'])
etc etc. It has a problem with the import at line 2.
I am using gunicorn to do
gunicorn -w 2 -b :5000 serveme:app
You have to run
sudo easy_install pip
then you're able to do
sudo pip install requests
sudo pip install python-firebase
Python was already installed, apparently you have to install pip again, brew doesn't like multiple downloads of the same package. So use the easy install for just pip.
Hope this helps someone else if they ever come across this.
I'm trying to get a Flask app hosted onto an IIS server and I'm stumbling at the last section. Here are the steps I've taken so far:
Installed Python 2.6.6 and Flask 0.10.1
Installed IIS 7.5
Downloaded PyISAPIe 1.1.0
Created a new web site in IIS
Turned on "Enable 32-Bit Applications" for my newly created Application Pool.
Created a Wildcard Script Map using the PyISAPIe .dll
Created the following file and named it 'test.py'
from Http.WSGI import RunWSGI
from Http import Env
from datetime import datetime
from flask import Flask
app = Flask(__name__)
app.debug = True
#app.route('/', defaults={'path': ''})
#app.route('/')
def catch_all(path):
s = "Path: %s\nTime: %s" % (path, datetime.now())
return s
def Request():
RunWSGI(app)
Used Chrome to go to localhost/test.py which returned:
The problem is this: my app only runs if you go to /test.py, but I'd like to run regardless of the URL. What do I need to do within IIS so that all requests, regardless of the URL, will use my flask app?
UPDATE: I've got it working, sort of. Here's what I did:
Replaced the Request function in Http.Isapi.py with the following:
.
app_root = "my path"
sys.path.append(app_root)
from test import Request
Used Chrome to go to localhost/test.py which returned:
I now have a new problem. When I go from my test app to the actual app I am greeted with the following traceback:
File "C:\Python26\Lib\site-packages\sqlalchemy\connectors\pyodbc.py", line 50, in dbapi
return __import__('pyodbc')
ImportError: DLL load failed: The specified module could not be found.
The issue isn't that I don't have pyodbc installed. My app works perfectly fine if it's booted up through the Flask.run() method.