Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python flask-cors ImportError: No module named 'flask-cors' Raspberry pi

I'm following the flask-cors tutorial from the documentation here: https://pypi.python.org/pypi/Flask-Cors

but when i installed it on my raspberry pi and run my python app i'm getting this error

Traceback (most recent call last): File "app.py", line 3, in <module> from flask_cors import CORS, cross_origin ImportError: No module named 'flask_cors'

here is my python script:

from flask import Flask
from Main import main
from flask_cors import CORS, cross_origin    
app = Flask(__name__)
CORS(app)
main = main() 

@app.route('/turn' ,methods=['GET', 'OPTIONS'])
def index():
  return main.turn()

if __name__ == '__main__': 
  app.run(debug=True, host='0.0.0.0')
like image 875
Nelson Candia Avatar asked Feb 09 '18 22:02

Nelson Candia


2 Answers

I had a similar issue where after installing flask_cors it was still giving me a ModuleNotFoundError. Try this:

sudo pip3 uninstall flask_cors
sudo pip3 install Flask-Cors

It's a subtle difference but it worked for me. Even though flask_cors appears to install a package and it's written that way in python when actually importing it, the actual package name installed with pip is Flask-Cors.

like image 54
Russell Molimock Avatar answered Sep 23 '22 19:09

Russell Molimock


I spent a day trying to resolve this. Here are my steps: First i closed my VSCODE and open it again, then run

pip uninstall flask
pip uninstall flask_cors
pip3 install flask
pipenv shell
pipenv install flask_cors
pip install pipreqs
git add .
git commit -am "New cor resolved"
git push heroku master
like image 36
Olu Ayeni Avatar answered Sep 22 '22 19:09

Olu Ayeni