Unable to import 'django.db'pylint(import-error)

FYI this is different from the other issue with the same name

I have an application that is workign correctly but in vsCode things like the from statement complain about the same issue.

from django.db import models

I have a .pylintrc file

[Master]
init-hook='import sys; sys.path.append("<project path>")'

Any ideas how I would fix the editor to be able to know where these imports are coming from. woudl be most welcome

I’ve noticed that for the following 3 lines where common.models is a local file it only complains when referencing the django from statements

from django.db import models
from django.utils import timezone
from common.models import TimeStampMixin

Where is Django installed? Do you use a virtual environment? Are you using Docker? I think knowing where your packages are installed would affect the answer to your question.

using

locate django

/Users//.pyenv/versions/3.7.9/lib/python3.7/site-packages/django

I’m not much of a VS Code user, but my best guess is that you need to instruct VS Code and the Python plugin where your Python environment is located. I’m sorry I don’t have the docs to point you to.

Once VS Code knows about your installed pyenv site packages, I think it will stop complaining about not finding the module.

in the generated .pyintrc file I edited this line to tell the linter to load django

# List of plugins (as comma separated values of python module names) to load,
# usually to register additional checkers.
load-plugins=django

.pylintrc file was generated by running

pylint --generate-rcfile > .pylintrc