Search code examples
pythonvisual-studio-codepylint

Pylint in VSCode goes mad when importing third-party moudles installed with pipenv by throwing no-member errors


I've got a pipenv virtualenv. I've added it to workplace settings:

"python.pythonPath": "/home/keddad/.local/share/virtualenvs/test-8gFlsF9b/bin/python",

It works, more or less. It starts a terminal in the pipenv by default, and it works flawlessly when I work with built-in modules. But if I install a module with pipenv, it starts working somehow strange. Let's say I've installed pydantic, import it and use like this:

import pydantic
class Foo(pydantic.BaseModel):
    bar: str

If I just run it, it works. Hinting in editor also works. But pylint marks this code as an error:

Module 'pydantic' has no 'BaseModel' member pylint(no-member)

Same thing happens if I just do

from pydantic import BaseModel

I've tried creating an .env file in project directory to specify PYTHONPATH in it like in one of the answers in this question, but it didn't really help. How do I fix this?


Solution

  • Well, as a workaround, one might try using another linter. flake8 works fine, for example