I too was facing this error while working with Python virtual environments. In my case, it was happening because I have installed Django on my virtual environment and my base environment didn't contain any module named Django.
Base(Global) environment
and when I use the same command inside my virtual environment (myDjangoEnv)
Fix:
- Now what I understood is that pylint uses the python interpreter to analyze our code and mark the error while we write the code.
- Since I have three python environments in my system, hence three different python interpreters are available to my VS Code.
So if VS code uses the Python interpreter from the base environment, it will not recognize the Django module (import Error). Therefore, you are required to change the Python interpreter to the one present in your virtual environment.
It sounds complicated but it is pretty simple:
- Click on the bottom left of the screen to change python interpreter.
- Select from the list of available Python interpreters. Make sure you select the appropriate interpreter with respect to the current project.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…