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')
If you import sys
and print(sys.path)
, this will show you where your available packages are installed.
In the event that pip installed flask_cors
outside of one of these directories, you should move the file to one of the directories or you can sys.path.append(<your path to flask_cors>)
.
To prevent pip from installing into a bad directory, I would recommend this answer
It worked for me finally
pip install -U flask-cors
If you are running your python script as sudo, then...
sudo pip install -U flask-cors
来源:https://stackoverflow.com/questions/48714769/python-flask-cors-importerror-no-module-named-flask-cors-raspberry-pi