Import "flask" could not be resolved from source Pylance (reportMissingModuleSource)
Solution 1
When I did not install the module "flask" in the Python environment currently used in VSCode:
Please use the command "pip --version
" to check the source of the module installation tool "pip", the module is installed at this location:
Then, we can use the command "pip show flask
" to check the installation location of the module "flask": (It checks whether the installation location of the module is consistent with the Python environment displayed in the lower left corner of VSCode.)
If the "reportMissingModuleSource" message is still displayed here, please reload VS Code.
(F1
, Developer: Reload Window
)
Solution 2
Are you using a Virtualenv? If so make sure that VSCode is using the virtualenv as your python interpreter, otherwise it will not be able to pick up the packages that you installed inside this virtualenv.
To do so, click on the Python interpreter in your bottom bar, you should get a list of possible python interpreters including your virtualenv.
Solution 3
I had a similar issue while trying to import flask on vscode. I fixed it by using anaconda. Simply you install the flask module in your created environment example screenshot.
How to create a virtual env in anaconda:
1. On the left sidebar, click on environments.
2. Click create (at the bottom).
3. At the pop-up window, give your vir.env a name
and select the language version.
4. Once created, you can start installing
different modules in your environment.
I hope that helps!
Solution 4
For Linux Mint and for those who have installed flask, but VSCode doesn't find it:
- check the Flask path:
pip show flask
(should be smth likeLocation: /home/<username>/.local/lib/python3.8/site-packages
- in VSCode click left bottom button and choose the python interpreter, in my case I changed it from
python3.9
topython3.8
as we can see it in the flaskpath
.
Solution 5
That's because you have not chosen your path correctly,
type:
pipenv --venv
then it will show you where your virtual env is installed. Check where the packages are installed in your env, and then type what comes to you from the shell\scripts or whatever\python, and the packages will work.
Related videos on Youtube
SARIM
Updated on November 04, 2021Comments
-
SARIM over 2 years
When I am writing
from flask import Flask
One Yellow line is coming up under flask and stating Import "flask" could not be resolved from source Pylance (reportMissingModuleSource) . Also, I am able to do the work with this package also successfully. But the thing is, I am not able to use autosuggesstions for Classes and methods very well.
Further:
- I have checked that flask is installed successfully.
- Also I visited this thread https://github.com/microsoft/pylance-release/issues/236
And I set up my settings.json in vscode as follows:
"python.analysis.extraPaths": [ "/media/sarimurrab/New Volume/COURSES/Flask/FlaskMigrateforDatabaseMigrations/2" ]
But Still, unable to resolve the error.
-
SARIM over 3 yearsI am not using virtual environment.
-
SARIM over 3 yearsIt is installed in the correct directory.
-
Jill Cheng over 3 years@Chaudhary Sarimurrab -Does the terminal still display "reportMissingModuleSource" after reloading VS Code?
-
SARIM over 3 yearsImport "wtforms" could not be resolvedPylancereportMissingImports
-
Jill Cheng over 3 years@Chaudhary Sarimurrab -Please install the module "wtforms" in the same Python environment.("pip install wtforms" or "pip3 install wtforms" )
-
Jill Cheng over 3 years@Chaudhary Sarimurrab -Which terminal did you install the module on? (Is VS Code internal terminal?) Please follow the commands in my answer to check if the module "wtforms" is installed in the same location.
-
Jill Cheng over 3 years@Chaudhary Sarimurrab -Please check whether the installation location of the module is consistent with the Python environment displayed in the lower left corner of VSCode.
-
SARIM over 3 yearsGot It. Thanks for resolving my issue.
-
SARIM over 3 yearsLet us continue this discussion in chat.
-
HasBert almost 3 yearsThank you i was searching for this answer!
-
neo5_50 almost 3 yearsEverything was correct for me with my virtual environment. Reloading was the only thing which got rid of the VS code error, thanks! Upvoting this now.
CMD/CTRl + shift + P
- search "reload window". -
Admin over 2 yearsAs it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
-
lucasresck over 2 yearsHi, @GinoMempin, I appreciate your comment. I have edited my question to include the citations to the other answers which already have mentioned the Python interpreter. I also developed more about the specific problem of Jupyter Notebooks inside VS Code, to make it more clear for those who are searching for solving this specific situation, given the fact this is not obvious at a first glance.