I am using the following setup
- MacOS 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, 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 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 setup 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.
Has anyone run into this issue and know a quick fix to get it working?
Thanks, jAC
None of the above worked for me. Adding both of the lines below to my settings.json file did, however.
The first line really just hides the linting error. Certainly not a permanent solution, but de-clutters the screen.
This answer gave me the second line: VS Code PyLint Error E0602 (undefined variable) with ProtoBuf compiled Python Structure
Maybe someone who understands python more than me can explain that one more.
My solution. This solution is only for the current project.
.vscode
.vscode/settings.json
setting.json
add the line (this is for python3)If you don't know where is located your python just run on the terminal the command
which python
orwhich python3
in will print the python location.This example works for dockerized Python - Django.
The solution from @Shinebayar G worked but this other one is a little bit more elegant:
Copied from https://github.com/Microsoft/vscode-python/issues/3840#issuecomment-463789294:
Given the following example project structure:
What I did to resolve this issue:
I have resolved import error by
CTRL+Shift+P
type Preferences settings and select the optionPreferences Open Settings (JSON)
and add a line"python.pythonPath": "/usr/bin/"
So JSON should look likeKeep other configuration lines if it is present. This should import all modules that you have installed using PIP for autocomplete.
In your workspace settings, you can set your python path like this:
Incase of pylint error install the following
Then create a file .pylintrc in the root folder and write the following