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.
Related
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
I don't know why my code doesn't work, I Import the library in the first line
from flask_sqlalchemy import SQLAlchemy
Knowing that I've already install flask_sqlalchemy
If it is a flask app you should run the app in virtualenv, otherwise simply running by python appName.py will give that error.
The other way is "set FLASK_APP=appName.py" then run flask run.
The first thing I'd check would be can you import the whole flask_sqlalchemy module:
import flask_sqlalchemy
If that works, it could be a case or spelling issue as that command works in my local environment.
It seems like you installed the wrong package. If you are using python3 you have to use python3 -m pip install <module>
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.
I tried the following simple code,
from flask import Flask
app = Flask(__name__)
#app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run()
it is running fine with,
python hello.py
but it gives an error when i try with python3
ImportError: cannot import name 'Flask'
A package is installed against a specific Python version/location. Installing Flask for Python 2 (which is probably what the python and pip commands are aliased to), doesn't install it for Python 3.
You should really just use virtualenv to control exactly what versions and packages you are using.
This creates a Python 3 environment and installs Flask:
virtualenv -p /usr/bin/python3 my_py3_env
source my_py3_env/bin/activate
pip install flask
When you open a new terminal, just source the activate script again to keep using the environment.