Skip to content
Home » Import flask could not be resolved from source Pylance

Import flask could not be resolved from source Pylance

To solve Import flask could not be resolved from source Pylance error follow below methods.

ERROR LOG

Import flask could not be resolved from source Pylance

How to solve Import flask could not be resolved from source Pylance ?

I encountered the problem you stated when I did not install the module “flask.” The reason for this is that the “flask” module is not installed in the Python environment that we are currently using in VSCode.
Please use the shortcut key Ctrl+Shift+’ to create a new VSCode terminal, which will automatically enter the currently selected environment, and then run the command “pip show flask” to see where the module “flask” is installed:
If the module still cannot be resolved, it is recommended that you reinstall the module “flask.”

Alternative to Solve Import flask could not be resolved from source Pylance

In case you are using a virtual environment;

  1. Create a virtual environment.
    python3.9 -m venv --without-pip virtual
  2. Activate the virtual environment.
    source virtual/bin/activate
  3. Install the pip for the created virtual environment.
    curl https://bootstrap.pypa.io/get-pip.py | python
  4. Install flask into the virtual env.
    pip install flask
  5. Create the python file.
    touch server.py
  6. Open file and import the module
  7. If it underlines again, install pip again while the .py file is still open.
    pip install flask

Other Solutions when using VS Code

  1. Firstly Create a Virtual Environment on your terminal
  2. then install your flask by pip install flask
  3. after install CTRL+SHIFT+P
  4. Search Python Interpreter
  5. Select Your virtual Environment\

Other way to solve Import flask could not be resolved from source Pylance

I ran into a similar problem when attempting to import flask into vscode. I corrected it with anaconda. Simply place the flask module in your newly formed environment.

How to make a virtual environment in Anaconda:

  1. Select Environments from the left sidebar.
  2. Select Create (at the bottom).
  3. In the pop-up window, name your vir .env and choose the language version.
  4. After you’ve constructed it, you may begin installing various modules in your environment.

Hope the above solution works.

Also read :

RuntimeError: cuDNN error: CUDNN_STATUS_NOT_INITIALIZED
WARNING: `pyenv init -` no longer sets PATH. Run `pyenv init` to see the necessary changes to make to your configuration.