jl__
jl__

Reputation: 21

Showing warning on vscode of import but not on any other editors

Hi all i'm trying import my defined module to "main" while this works fine on sublime text & Pycharm. VS Code doesn't accept my define even it's on same path/folder. Import "wfg" could not be resolved only editor where it shows warning is vscode any tips?

Upvotes: 1

Views: 1488

Answers (3)

Steven-MSFT
Steven-MSFT

Reputation: 8431

It's a linting mistake.

Does it prompt by Pylance?

If it is, you can add this in the settings.json file:

  "python.analysis.extraPaths": [
    "${workspaceFolder}/[some paths]/[Parent folder of main.py]",
  ],

If it is not, please let me know.

Update:

Pylance needs to know which import resolution paths to use. By default, it uses the root of your workspace. You will need to add these additional paths using the "python.analysis.extraPaths" setting like this: "python.analysis.extraPaths": ["base", "utils", "dataset", ""] Note that these paths are relative to your workspace root directory.

From the developer explain.

Upvotes: 1

jl__
jl__

Reputation: 21

Hey actually that worked why i didn't though that. Works now when i open folder too.

Upvotes: 0

Adarsh Raj
Adarsh Raj

Reputation: 425

May any one of this helps:

If you have opened your project in vscode with more than your main project or we can say that if you have open your project in vscode with parent folder of your project folder. Then vscode will shows this warning. So for this you have to open directly main folder of your project then it will works fine.

Some Hack solution but it seems not to work everywhere: Import something like this if it is in same folder: ./modulename.py

or in another folder then : ../onebackdir/modulename.py

Upvotes: 0

Related Questions