Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to import 'django.http'pylint(import-error) [closed]

Specs:

  • Visual Studio Code 2019
  • lattest pip version
  • Django 2.2+ version
  • Python latest 3.7 version
like image 715
krishna kakade Avatar asked Oct 15 '19 06:10

krishna kakade


People also ask

How do I fix Pylint import error in VSCode?

To solve unresolved import error in Python, set your Python path in your workspace settings. If you are working with Visual Studio Code and import any library, you will face this error: “unresolved import”. Then reload the VSCode, and it will fix that error.

What is import error in Django?

db' pylint(import-error) showing up. This is because VS Code is not running the Virtual Environment of the app. To fix it, run cmd-shift-p (or click View -> Command Palette and run the command Python: Select Interpreter. VS Code will show you a list of Python interpreters found.

What is Pylint Django?

pylint-django is a Pylint plugin for improving code analysis when analysing code using Django. It is also used by the Prospector tool.


2 Answers

Just solved it, thanks to this SO question (VS Code error when importing Django module).

  1. Open the Command Palette (in the View menu)
  2. Type Python: Select Interpreter
  3. Choose the option with your virtual environment
like image 107
Steve Nyholm Avatar answered Nov 10 '22 03:11

Steve Nyholm


Chances are you installed into a Python environment different from the one you have chosen in VS Code. There are two ways to solve this.

The best solution is to create a virtual environment and then install into it using python -m pip. You should never use just the straight pip command as that will install into the last Python you installed which happens to be set earliest in your PATH.

The other option is to figure out which Python environment you installed Django into and make sure that's the one you have selected in VS Code.

Details on environment selection and such can be found at https://code.visualstudio.com/docs/python/environments.

like image 41
Brett Cannon Avatar answered Nov 10 '22 03:11

Brett Cannon