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.

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.

If you're running flask from a conda environment, install flask_cors with conda:
conda install flask_cors
Receiving ModuleNotFoundError: No module named 'flask_cors' during runtime
Trouble Setting Up Flask_Cors in PyCharm on Mac
python - How to solve Import "flask_cors" could not be resolved from source - Stack Overflow
Flask-Cors not working while using url_prefix in blueprints
Hi All,
Trying to set up flask_cors in PyCharm on Mac. I have a Venv in my directory, I even installed Flask_Cors via terminal in that venv within my project, and it says it was set up fine.
Location: /Users/me/Documents/pythonProject1/my_venv/lib/python3.11/site-packages
It says that the interpreter I'm using is a 3.11 at: /Users/me/myprojname/bin/python
The issue is that I have is that Python will not recognize/find the flask_cors package in PyCharm. I get the error message: (unresolved reference flask_CORS). Any thoughts?
I've even tried to find it through the Pycharm/settings/add package to the interpreter list.
What might I be doing wrong? Did I install flask in the wrong place or something? As far as I can tell my project is set up like the following:
/my_project
/my_venv
__init__.py
app.py # This contains your entire Flask app
Thanks!
from flask import Flask,request,jsonify
from flask_cors import CORS,cross_origin
app = Flask(__name__)
CORS(app)
app.config['ENV'] = "development"
@app.route('/auth',methods=["POST"])
@cross_origin()
def login():
res=request.get_json()
em=res["email"]
pwd=res["password"]
print(em+"\t"+pwd)
return "success"
if __name__ == "__main__":
app.run(debug=True)
https://flask-cors.readthedocs.io/en/latest/
Allow access to all apis that starts with /api from all origins.
cors = CORS(app, resources={r"/api/*": {"origins": "*"}})
or if you are testing from local try
cors = CORS(app, resources={r"/api/*": {"origins": ["http://localhost:5000/*"]}})
from flask import Flask,request,jsonify
from flask_cors import CORS,cross_origin
app = Flask(__name__)
cors = CORS(app, resources={r"/*": {"origins": "*"}})
app.config['ENV'] = "development"
@app.route('/auth',methods=["POST"])
@cross_origin()
def login():
res=request.get_json()
em=res["email"]
pwd=res["password"]
print(em+"\t"+pwd)
return "success"
if __name__ == "__main__":
app.run(debug=True)
» pip install flask-cors
It worked for me finally
pip install -U flask-cors
If you import sys and print(sys.path), this will show you where your available packages are installed.
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>).
To prevent pip from installing into a bad directory, I would recommend this answer
After I tried others suggestions and answers. Here's what I use, which works.
Steps:
pip install flask flask-corsCopy and paste this in
app.pyfile
Code
from flask import Flask, jsonify
from flask_cors import CORS, cross_origin
app = Flask(__name__)
CORS(app, support_credentials=True)
@app.route("/login")
@cross_origin(supports_credentials=True)
def login():
return jsonify({'success': 'ok'})
if __name__ == "__main__":
app.run(host='0.0.0.0', port=8000, debug=True)
python app.py
Note: be sure in your client's ajax configuration has the following:
$.ajaxSetup({
type: "POST",
data: {},
dataType: 'json',
xhrFields: {
withCredentials: true
},
crossDomain: true,
contentType: 'application/json; charset=utf-8'
});
If one wonders, support_credentials=True just means it sends cookies along the payload back and forth.
Flask has the flask-cors module. Following is the code snippet as well as the procedure.
pip install -U flask-corsAdd this lines in your flask application:
from flask import Flask from flask_cors import CORS, cross_origin app = Flask(__name__) CORS(app) @app.route("/") def helloWorld(): return "Hello world"
See more by clicking on this link
- Firstly, create a virtual environment on your terminal.
- Then install Flask by running pip install flask.
- After installing, press CTRL+SHIFT+P.
- Search for Python Interpreter.
- Select your virtual environment.
The problem will be fixed. I have also faced the same issue, but I resolved it by following this procedure.
When I did not install the module "flask", I ran into the problem you described:

The reason is that the module "flask" is not installed in the Python environment we currently use in VSCode.
Please use the shortcut key Ctrl+Shift+` to open a new VSCode terminal, it will automatically enter the currently selected environment, and then use the command "pip show flask" to check the installation location of the module "flask":

If it still shows that the module could not be resolved, it is recommended that you reinstall the module "flask".