我在通过 pip 安装 flask_cors 时遇到问题

I have a trouble with install flask_cors by pip

AJackTis-MacBook-Air:API ajackti$ pip install flask_cors

DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.

Requirement already satisfied: flask_cors in /usr/local/lib/python2.7/site-packages (3.0.7)

Requirement already satisfied: Six in /usr/local/lib/python2.7/site-packages (from flask_cors) (1.12.0)

Requirement already satisfied: Flask>=0.9 in /usr/local/lib/python2.7/site-packages (from flask_cors) (1.0.2)

Requirement already satisfied: Werkzeug>=0.14 in /usr/local/lib/python2.7/site-packages (from Flask>=0.9->flask_cors) (0.15.2)

Requirement already satisfied: click>=5.1 in /usr/local/lib/python2.7/site-packages (from Flask>=0.9->flask_cors) (7.0)

Requirement already satisfied: Jinja2>=2.10 in /usr/local/lib/python2.7/site-packages (from Flask>=0.9->flask_cors) (2.10)

Requirement already satisfied: itsdangerous>=0.24 in /usr/local/lib/python2.7/site-packages (from Flask>=0.9->flask_cors) (0.24)

Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python2.7/site-packages (from Jinja2>=2.10->Flask>=0.9->flask_cors) (0.23)

不过,我已经安装了库flask_cors。但是导入的时候出错了

AJackTis-MacBook-Air:API ajackti$ python

>>> from flask_cors import CORS
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named flask_cors

我希望我能找到解决办法。谢谢你帮助我

破解

您的一个技巧是将安装路径添加到您的 python 路径:

import sys
sys.path.append("/usr/local/lib/python2.7/site-packages")
\ your code

解决方案

所述,您可以临时和永久更改安装路径 例子: pip install flask-cors --target /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages