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

41,272

Solution 1

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

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:

  1. check the Flask path: pip show flask (should be smth like Location: /home/<username>/.local/lib/python3.8/site-packages
  2. in VSCode click left bottom button and choose the python interpreter, in my case I changed it from python3.9 to python3.8 as we can see it in the flask path.

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.

Share:
41,272

Related videos on Youtube

SARIM
Author by

SARIM

Updated on November 04, 2021

Comments

  • SARIM
    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:

    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.

  • SARIM
    SARIM over 3 years
    I am not using virtual environment.
  • SARIM
    SARIM over 3 years
    It is installed in the correct directory.
  • Jill Cheng
    Jill Cheng over 3 years
    @Chaudhary Sarimurrab -Does the terminal still display "reportMissingModuleSource" after reloading VS Code?
  • SARIM
    SARIM over 3 years
    Import "wtforms" could not be resolvedPylancereportMissingImports
  • Jill Cheng
    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
    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
    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
    SARIM over 3 years
    Got It. Thanks for resolving my issue.
  • SARIM
    SARIM over 3 years
  • HasBert
    HasBert almost 3 years
    Thank you i was searching for this answer!
  • neo5_50
    neo5_50 almost 3 years
    Everything 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
    Admin over 2 years
    As 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
    lucasresck over 2 years
    Hi, @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.