2

I want to open a folder at the level above a Django project directory (project_parent below) in VS Code and have the linter correctly resolve the Django project imports:

| project_parent
| -- | django_project_dir
| -- | -- | manage.py

If I do this, the linter is confused and I get a bunch of warnings on imports from the Django modules in the project:

unresolved import 'module.models' Python(unresolved-import)

If I open VS Code at the the Django project folder level, the linter resolves all of the imports. This isn't ideal though because I have to close and re-open VS Code at the level above to see other related code (Ansible, bash scripts, etc.)

My question is how to update VS Code settings to add the Django project directory to the linter path?

Env:

VS Code: 1.40.1
Python: 3.7.2
Django: 2.2.1

Related question: Pylint "unresolved import" error in visual studio code

  • the solution here is just to open the project at the level of the Django project dir which I don't want to do.
  • my issue is not related to "python.pythonPath" setting, the python path is fine and all of the package level imports are resolved by the linter.
it's-yer-boy-chet
  • 1,917
  • 2
  • 12
  • 21

1 Answers1

4

You want to update your "python.autoComplete.extraPaths" setting to include the sub-directory where you have your code that isn't being found.

Brett Cannon
  • 14,438
  • 3
  • 45
  • 40