Cannot import 'flask' in python
Question:
I am using the following code:
from flask import Flask, jsonify, request
However, I get an error from the word "flask":
Import "flask" could not be resolved
I tried this answer to reinstall the "flask" package but still got the error.
How can I fix this error? Appreciate if someone can advise. Thank you in advance!
Answers:
First, enter pip3 show flask
in the terminal. It will display something like this:
Name: Flask
Version: 2.2.2
Summary: A simple framework for building complex web applications.
Home-page: https://palletsprojects.com/p/flask
Author: Armin Ronacher
Author-email: [email protected]
License: BSD-3-Clause
Location: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages
Requires: click, importlib-metadata, itsdangerous, Jinja2, Werkzeug
Required-by:
If the location says /Versions/3.7/
(maybe yours is different from mine), it means you added the package in Python 3.7 (maybe yours and mine are different). Remember the Python version, you will need it later.
Then, click ⌘ + ⇧ + P . After that, select Python: Select Interpreter
. Then, choose the Python version where you added the package. The error may go away (mine went away).
I am using the following code:
from flask import Flask, jsonify, request
However, I get an error from the word "flask":
Import "flask" could not be resolved
I tried this answer to reinstall the "flask" package but still got the error.
How can I fix this error? Appreciate if someone can advise. Thank you in advance!
First, enter pip3 show flask
in the terminal. It will display something like this:
Name: Flask
Version: 2.2.2
Summary: A simple framework for building complex web applications.
Home-page: https://palletsprojects.com/p/flask
Author: Armin Ronacher
Author-email: [email protected]
License: BSD-3-Clause
Location: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages
Requires: click, importlib-metadata, itsdangerous, Jinja2, Werkzeug
Required-by:
If the location says /Versions/3.7/
(maybe yours is different from mine), it means you added the package in Python 3.7 (maybe yours and mine are different). Remember the Python version, you will need it later.
Then, click ⌘ + ⇧ + P . After that, select Python: Select Interpreter
. Then, choose the Python version where you added the package. The error may go away (mine went away).