Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pylint "unresolved import" error in Visual Studio Code

I am using the following setup

  • macOS v10.14 (Mojave)
  • Python 3.7.1
  • Visual Studio Code 1.30
  • Pylint 2.2.2
  • Django 2.1.4

I want to use linting to make my life a bit easier in Visual Studio Code. However, for every import I have states "unresolved import". Even on default Django imports (i.e. from django.db import models).

I presume it is because it is not seeing the virtual environment Python files.

Everything works just fine, but it's starting to get annoying.

The interpreter choices I have are all system versions of Python. It does not seem to see my virtual environment Python at all (it is not in the same directory as my workspace, so that part makes sense).

If I set up the python.PythonPath in the settings.json file, it just ignores it and does not list my virtual environment path as an option. I also tried setting it up in my global Python settings, but it also does not show up.

Is there a quick fix to get it working?

like image 400
jAC Avatar asked Dec 27 '18 04:12

jAC


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.

How do I resolve import errors in VSCode?

Set the correct Python path in VSCode In order to fix Unresolved Import in VSCode, you have to set python. pythonPath key in the settings to the correct value. You can quickly open the settings. json editor by accessing File > Preferences or press Ctrl + , key combination.

How do I get PyLint on VSCode?

To enable linters, open the Command Palette (Ctrl+Shift+P) and select the Python: Select Linter command. The Select Linter command adds "python. linting.

What is PyLint in Visual Studio?

PyLint, a widely used tool that checks for errors in Python code and encourages good Python coding patterns, is integrated into Visual Studio for Python projects.


1 Answers

The accepted answer won't fix the error when importing own modules.

Use the following setting in your workspace settings .vscode/settings.json:

"python.autoComplete.extraPaths": ["./path-to-your-code"], 

Reference: Troubleshooting, Unresolved import warnings

like image 103
Shinebayar G Avatar answered Sep 26 '22 12:09

Shinebayar G