0
votes
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)

Although, I have installed library flask_cors. But when I import it, it was an error.

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

I hope I find a solution to fix it. Thanks for helping me

1
I suggest a checklist after that we can help you more: 1- can you check pip list and see if the flask_cors is there? 2- And make sure that your python refers to python2.7, not another version of python. 3- make sure that you are not in a virtual environment;Mehdi
Can you confirm that you are using python 2.7(maybe there is another installation of python on your computer, and you are not in avirtual environment. use python --version for the first one.Mehdi
for checking if you are using venv take a look at this:stackoverflow.com/a/1883251/2754195Mehdi
if you are sure about where your python code is running. please run this command pip install flask-cors --upgrade or pip install -U flask-corsMehdi

1 Answers

1
votes

Hack

One hack for you is to add the installation path to your python path:

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

Solution

as said in this answer you can change the path of installation temporary and permanently example: pip install flask-cors --target /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages