Friday, July 30, 2021

how to fix "Import "django.contrib.auth" could not be resolved from sourcePylance" in Django application development?

 when I try to import a library to the project. I spot a curly underline for the library that i just imported.

I hovered the mouse to the underneath, the warming message as following

    "Import "django.contrib.auth" could not be resolved from sourcePylance"


the root cause of this issue is related to the VS Code workspace configuration. we have to add this line to get ride of the error message.

{
    "python.pythonPath""/venv/bin/python",
}

Since I did not have the .vscode folder when I setup my django project with command line window.

I have to manually create a .vscode folder under the project and add the settings.json file inside it.

I put the above setting in the settings.json file.  The warming message finally resolved.










update: if the above solution still doesn't work

you can change the python interpreter for the current project by doing the following

  • use Ctrl-Shift-p to open command palette
  • type python interpreter in the command palette
  • select Enter interpreter path
  • find the python.exe file under your venv\scripts folder


No comments:

Post a Comment