Reputation: 7782
To state from the get go this is no criticism of pythonanywhere, but I want to run a script that used to work using the line:
from flask_cors import CORS
But I get the following error mesage:
ModuleNotFoundError: No module named 'flask_cors'
Then tried to install in my version of python:
pip3.9 install Flask-Cors
The result was:
Defaulting to user installation because normal site-packages is not writeable Looking in links: /usr/share/pip-wheels Requirement already satisfied: Flask-Cors in ./.local/lib/python3.9/site-packages (3.0.10) Requirement already satisfied: Six in /usr/local/lib/python3.9/site-packages (from Flask-Cors) (1.16.0) Requirement already satisfied: Flask>=0.9 in /usr/local/lib/python3.9/site-packages (from Flask-Cors) (2.0.0) Requirement already satisfied: Werkzeug>=2.0 in /usr/local/lib/python3.9/site-packages (from Flask>=0.9->Flask-Cors) (2.0.1) Requirement already satisfied: itsdangerous>=2.0 in /usr/local/lib/python3.9/site-packages (from Flask>=0.9->Flask-Cors) (2.0.1 ) Requirement already satisfied: click>=7.1.2 in /usr/local/lib/python3.9/site-packages (from Flask>=0.9->Flask-Cors) (7.1.2) Requirement already satisfied: Jinja2>=3.0 in /usr/local/lib/python3.9/site-packages (from Flask>=0.9->Flask-Cors) (3.0.1) Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.9/site-packages (from Jinja2>=3.0->Flask>=0.9->Flask-C ors) (2.0.1) 15:33 ~$ pip show Flask-Cors Name: Flask-Cors Version: 3.0.10 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: /home/elksie5000/.local/lib/python3.9/site-packages Requires: Six, Flask
What gives and how do I fix it?
Upvotes: -1
Views: 2504
Reputation: 1
The ModuleNotFoundError: No module named 'flask_cors' error indicates that either:
The flask_cors package is not installed in the current Python environment.
The flask_cors package is installed but not correctly linked or recognized by the current Python environment.
Install flask-cors by running: pip install -U flask-cors
This code sets up a basic Flask application with Cross-Origin Resource Sharing (CORS) enabled, allowing the Content-Type header to be shared across different origins.
from flask import Flask from flask_cors import CORS
Initialize the Flask application
app = Flask(name)
Enable CORS for the application
cors = CORS(app)
Configure CORS headers
app.config['CORS_HEADERS'] = 'Content-Type'
Reinstall flask-cors.
Uninstall the package: pip uninstall flask-cors
Reinstall the package: pip install flask-cors
Sometimes dependency resolution can fail during the first installation attempt, especially if there are conflicting or missing dependencies. Reinstalling the package ensures that pip tries again to resolve dependencies, pulling in any updates that might resolve conflicts.
Upvotes: -1
Reputation: 72
I think you should try the following:
(I think you want to make an API using cors maybe)
Upvotes: -2