Python flask-cors ImportError:没有名为"flask-cors"的Raspberry pi模块

Python flask-cors ImportError:没有名为

问题描述:

我正在按照此处文档中的flask-cors教程进行操作: https://pypi.python.org/pypi/Flask-Cors

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

但是当我将其安装在树莓派上并运行python应用程序时,出现此错误

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'

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'

这是我的python脚本:

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

如果您import sysprint(sys.path),这将向您显示可用软件包的安装位置.

If you import sys and print(sys.path), this will show you where your available packages are installed.

如果pip将flask_cors安装在这些目录之一之外,则应将文件移至其中一个目录,否则可以sys.path.append(<your path to flask_cors>).

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

为防止pip安装到错误的目录中,我建议此答案

To prevent pip from installing into a bad directory, I would recommend this answer