Search code examples
pythondjangovisual-studio-codemoduledjango-filters

How do you solve Import "django_filters.views" could not be resolvedPylance error


I suddenly received this error when I opened vscode:

Import "django_filters.views" could not be resolvedPylance(reportMissingImports)

I was programming a django project about a month ago using vscode, but I didn't work on the project for about a month since I had other things to do. However, when I opened my vscode to start working on the project again, I received the above error. New edits in the code seem to be a grey color now as well. I think vscode got automatically updated while I was away, but I have no idea why this issue is occurring. I hope you guys could help me find the problem. If there is any information you need, please comment below. Thanks.

I don't know if this would help, but I found the following article that states that "Pylance is now the default language server for Python in Visual Studio Code, providing IntelliSense functionality as of the May 2021 release of the Python Extension for VS Code."


Solution

  • Yes, it is related to Pylance Language Server.

    You need to add this in your settings.json file(if django_filters folder just under the folder you opened in the VSCode):

    "python.analysis.extraPaths": ["${workspaceFolder}/django_filters"]
    

    You can refer to here and here for more details.

    Update:

    If you want to roll back, you can add or update this configuration in the settings.json file:

    "python.languageServer": "JediLSP",
    

    And

    ${workspaceFolder} means the path of the folder opened in VS Code.

    You can refer to the official docs.