0
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

AJackTi
  • 63
  • 1
  • 6
  • 2
    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 May 04 '19 at 12:09
  • yeah. Flask-Cors in this list. but I can't use this. Do you have any solution for this? @Mehdi – AJackTi May 04 '19 at 12:19
  • 2
    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 a`virtual environment`. use `python --version` for the first one. – Mehdi May 04 '19 at 12:24
  • 2
    for checking if you are using `venv` take a look at this:https://stackoverflow.com/a/1883251/2754195 – Mehdi May 04 '19 at 12:25
  • 2
    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-cors` – Mehdi May 04 '19 at 12:27
  • I use python to code anything. I don't want to use venv to run code. – AJackTi May 04 '19 at 12:31
  • 1
    I'm not suggesting you use venv to run your code, I'm trying to troubleshoot your problem. BTW what about `pip install flask-cors --upgrade or pip install -U flask-cors` – Mehdi May 04 '19 at 12:32
  • and pip which i am using is of python2.7. When running your command(pip install flask-cors --upgrade or pip install -U flask-cors) It is still an error – AJackTi May 04 '19 at 12:33
  • 2
    Possible duplicate of [Python flask-cors ImportError: No module named 'flask-cors' Raspberry pi](https://stackoverflow.com/questions/48714769/python-flask-cors-importerror-no-module-named-flask-cors-raspberry-pi) – Mehdi May 04 '19 at 12:35
  • 2
    take a look at this answer: https://stackoverflow.com/a/48715014/2754195 – Mehdi May 04 '19 at 12:35
  • Yes. I have a list of sys.path. And now Will I do next? Hope your help :( – AJackTi May 04 '19 at 12:40
  • 2
    take a look at the path and check if flask-cors exist there or not. – Mehdi May 04 '19 at 12:41
  • It doesn't have in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages. – AJackTi May 04 '19 at 12:47
  • Can I install it in this folder? – AJackTi May 04 '19 at 12:48

1 Answers1

1

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

Mehdi
  • 1,043
  • 12
  • 29
  • OK. This is a solution for me. Thank you so much. – AJackTi May 04 '19 at 13:09
  • 2
    If you are using other version of Python, you should change it in the command. For example: if you use `python 3.6` the command would be `pip install flask-cors --target /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages` – Magofoco Oct 12 '19 at 18:12