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

老子叫甜甜 提交于 2019-12-02 01:19:40

问题


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')

回答1:


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




回答2:


It worked for me finally

pip install -U flask-cors




回答3:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!