Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import [Module] could not be resolved (PylancereportMissingImports), with module in the same folder/directory

The first few lines of the code of evaluation.py:

import os
import torch
from torch.nn import functional as F
from torch.utils.data import DataLoader
import numpy as np
from dataset import CLSDataset # warning is reported here
from tqdm import tqdm

The structure of the folder:

./
|-dataset.py
|-dictionary.py
|-evaluation.py
|-model.py
|-models/
  |-[some files]
|-__pycache__
|-train.py

Notice that dataset.py is in the same folder as that of evaluation.py and https://github.com/microsoft/pylance-release/blob/main/TROUBLESHOOTING.md#unresolved-import-warnings says that The language server treats the workspace root (i.e. folder you have opened) as the main root of user module imports. But it still throws an warning of "Import dataset could not be resolved".

I tried to add the

{
    "python.analysis.extraPaths": ["./"]
}

on the settings.json of both local and remote files, but it does not help.

like image 893
core_exe Avatar asked Oct 16 '25 03:10

core_exe


1 Answers

In VSCode, go to the main window and do the following:

  1. Do Ctrl+Shift+P (for Windows) and Command+Shift+P (for Mac)
  2. Scroll and go to Python Select Interpreter
  3. Now select whichever python version is installed in your system.
  4. You're good to go!

Do upvote if it helps you!

like image 163
Ayush Gupta Avatar answered Oct 18 '25 17:10

Ayush Gupta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!