Issue
from flask import Flask
from flask_cors import CORS
app = Flask(__name__)
CORS(app)
@app.route('/')
def home():
return 'Hello, World!'
if __name__ == '__main__':
app.run(debug=True)
It's currently 3.10.0 version and I've tried sys.path.append, pip install -u flask_cors pip3 install flask_cors, etc. It doesn't work for people who have the same problem as me.
If you move the cursor to flask_cors, the message No module named 'flask_cors' appears.
Also, when I run python app.py, I get ModuleNotFoundError: No module named 'flask_cors'.
Any help would be appreciated.
Solution
I had the same issue some months ago, can you check that all packages are correctly installed with pip freeze
.
import sys
import os
from flask import Flask, request, jsonify, redirect
try:
from flask_cors import CORS, cross_origin # The typical way to import flask-cors
except ImportError:
# Path hack allows examples to be run without installation.
import os
parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
os.sys.path.insert(0, parentdir)
from flask_cors import CORS, cross_origin
app = Flask(__name__)
CORS(app)
My requirments for this code :
Flask==1.1.1
Flask-Cors==3.0.8
Flask-Migrate==2.5.2
Flask-Script==2.0.6
Flask-SQLAlchemy==2.4.0
psycopg2-binary==2.8.3
Answered By - SidoShiro92
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.