Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unresolved Imports in VS Code Django Project

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.
like image 768
it's-yer-boy-chet Avatar asked Jan 20 '26 03:01

it's-yer-boy-chet


1 Answers

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

like image 59
Brett Cannon Avatar answered Jan 22 '26 16:01

Brett Cannon



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!