I am trying to install Flask
with the following command:
pip install flask
But pip returns:
Requirement already satisfied: flask in /home/john/anaconda3/lib/python3.11/site-packages (3.0.0)
Requirement already satisfied: Werkzeug>=3.0.0 in /home/john/anaconda3/lib/python3.11/site-packages (from flask) (3.0.1)
Requirement already satisfied: Jinja2>=3.1.2 in /home/john/anaconda3/lib/python3.11/site-packages (from flask) (3.1.2)
Requirement already satisfied: itsdangerous>=2.1.2 in /home/john/anaconda3/lib/python3.11/site-packages (from flask) (2.1.2)
Requirement already satisfied: click>=8.1.3 in /home/john/anaconda3/lib/python3.11/site-packages (from flask) (8.1.7)
Requirement already satisfied: blinker>=1.6.2 in /home/john/anaconda3/lib/python3.11/site-packages (from flask) (1.7.0)
Requirement already satisfied: MarkupSafe>=2.0 in /home/john/anaconda3/lib/python3.11/site-packages (from Jinja2>=3.1.2->flask) (2.1.1)
(I have anaconda and conda installed)
My imports show an error:
All that my code contains is:
from flask import *
I am using Ubuntu Budgie 22.04. Someone please provide an answer. . .
2
Answers
Pip installing something and it not being recognised is (as far as I know) always a symptom of mismatching python executables. The python you’re using to run a file might be different from the python you’re using to execute the script, and that one might be different from the one your IDE is using to check if the imports exist.
You appear to have already done this in the comments, but the first step is to pip install via the python executable:
After this, everything should be installed, and should work when you execute the files from the same command line like:
However, your IDE might still disagree at this point (the editor shows an error, even tough the code runs fine), which means that the IDE is using a different python interpreter than you are from the console (even your IDE’s console).
To fix this, and any of these issues, you should select the right intepreter (find it with
which python
) in your IDE. On visual studio code, The interpreter selection is here (Screenshot editied in by D.L.):if you have anaconda then you should use
conda install <package>
.if you have downloaded python from the web on the https://www.python.org website (which is what i do), then you should be using
python -m pip install <package>
.I believe that the general rule is this: