Thursday, April 28, 2022

[FIXED] How to resolve VSCode import warnings with python scripts?

Issue

VSCode gives a warning whenever I import a python file from the same directory, but in practice everything works fine when the scripts run.

In a sample directory:

root_folder
+-- __init__.py (empty)
+-- __main__.py (empty)
+-- __import.py (contains Parent class)
+-- toImport.py (contains Child(Parent) class)

I try the following in toImport.py:

from __import import Parent

class Child(Parent): ...

Although I keep getting a warning: unresolved import even if it works. How can I resolve this issue or is it a VSCode issue?


Solution

Add this to your projects .vscode/settings.json file.

{
  "python.autoComplete.extraPaths": ["./root_folder"]
}


Answered By - GollyJer
Answer Checked By - David Goodson (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.