Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import "flask" could not be resolved from source Pylance (reportMissingModuleSource)

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:

  1. I have checked that flask is installed successfully.
  2. 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.

like image 865
SARIM Avatar asked Jan 19 '21 06:01

SARIM


People also ask

How do I enable VS code virtual env?

Open Visual Studio Code in your project's folder. Click Yes ; and your venv is ready to go. Open a new terminal within VSCode Ctrl + Shift + P and you'll see that venv is getting picked up; e.g.: (venv) ... Activate.


2 Answers

When I did not install the module "flask" in the Python environment currently used in VSCode:

enter image description here

Please use the command "pip --version" to check the source of the module installation tool "pip", the module is installed at this location:

enter image description here

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.)

enter image description here

If the "reportMissingModuleSource" message is still displayed here, please reload VS Code.

(F1, Developer: Reload Window)

enter image description here

like image 67
Jill Cheng Avatar answered Oct 16 '22 13:10

Jill Cheng


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.

like image 38
Marius Kimmina Avatar answered Oct 16 '22 11:10

Marius Kimmina