2

I have installed flask_cors like so: pip install Flask-Cors pip3 install -U flask-cors, pip install -U flask-cors pip install flask-cors --upgrade

This is my code:

from flask import Flask
from flask_cors import CORS, cross_origin

app = Flask(__name__)
CORS(app)

any answer to solve this error is appreciated

enter image description here Thankyou

  • Does this answer your question? [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) – Prophet Aug 17 '21 at 07:21
  • 1
    i used each and every command mentioned over there still the error persists.@Prophet – Akhil Seeramsetty Aug 17 '21 at 07:26
  • Did you use any virtual environment? Check if the module is installed in your current used python interpreter. – Molly Wang-MSFT Aug 17 '21 at 08:25
  • Please let me know how can i check it.? @MollyWang-MSFT – Akhil Seeramsetty Aug 17 '21 at 09:39
  • Run `pip show module_name` in integrated Terminal and see if its location is `your current python interpreter\lib\site-packages`. You may edit and upload this screenshot in your question. – Molly Wang-MSFT Aug 17 '21 at 09:40
  • Please check it, ``` Name: Flask-Cors Version: 3.0.3 Summary: A Flask extension adding a decorator for CORS support Home-page: https://github.com/corydolphin/flask-cors Author: Cory Dolphin Author-email: corydolphin@gmail.com License: MIT Location: c:\users\akhil\python\python39\lib\site-packages Requires: Flask, Six Required-by: PS C:\Users\AKHIL\Downloads\2_automation (1)\2_automation> ``` @Molly Wang-MSFT – Akhil Seeramsetty Aug 17 '21 at 09:53
  • Please check my answer and if there's anything missed or you want to know, please comment there. – Molly Wang-MSFT Aug 17 '21 at 09:58

1 Answers1

8

The first case:

Install the module in not current used python interpreter. Use pip show flask_cors to check if its location is your current python interpreter\lib\site-packages. If not, after selecting python interpreter, open a new integrated Terminal then use command to reinstall modules.

The second case:

You've installed the module successfully in current used python environment, then import module in code, but Pylance still throws the error ImportError: No module named 'flask_cors'<ReportMissingImports>. What you need to do is opening Command Palette and choose Reload Window, the error should go away.

Please have a try. enter image description here

Molly Wang-MSFT
  • 7,943
  • 2
  • 9
  • 22
  • Please check my image once i have uploaded it, and let me know what changes can i make on it. Your support is Very Much Apprecated. @Molly Wang-MSFT – Akhil Seeramsetty Aug 17 '21 at 10:08
  • @AkhilSeeramsetty. Press `Ctrl+Shift+P` to open Command Palette and choose **Python: Select interpreter**, if the current path shown in box is `C:\users\akhil\python\python39\python.exe`, then `flask_cors` is installed correctly in your selected environment. You need to save your files then reload window. – Molly Wang-MSFT Aug 18 '21 at 01:19
  • @AkhilSeeramsetty. You're welcome. Happy Coding:) – Molly Wang-MSFT Aug 18 '21 at 05:18
  • Thanks! This got me in the right area. For me I needed to select my Python 3.9.9 64-bit Interpreter located C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python3.9_3.9.25544.0_x64_... which is NOT the recommended one. – NewtonEntropy Dec 13 '21 at 22:21
  • @NewtonEntropy. Glad your question has been solved :) – Molly Wang-MSFT Dec 14 '21 at 01:10
  • I have a similar problem when running in a bash shell. I got the same error. My problem is solved by opening a new terminal with fresh activation of the venv environment. – Yu Shen Jan 09 '23 at 15:28