Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code, pylint complaining about "Unable to import XXX"

I am using Visual Studio Code to work on a large python project with many modules.

My settings.json looks like this:

{
    "python.linting.pylintEnabled": true,
    "python.linting.enabled": true,
    "python.autoComplete.extraPaths": [
        "C:/Users/.../repos/platform",
    ],
    "python.linting.pylintPath": "pylint"
}

After that inside the code. I am getting a ton of error on all import modules which are inside the platform-folder. I have python3 installed with python extensions and pylint installed as well.

I have searched for over an another and tried many different suggestions but none has worked for me so far.

like image 599
theAlse Avatar asked Jan 01 '23 16:01

theAlse


2 Answers

The Current Problem you are facing is not regarding code formatting (by pylint). you would rather want to choose the interpreter you want to have Intellisense for. they are provided in docs as followed. link. Hope this helps. If it's TL;DR for you. just press F1 on vscode window and type Python:Select you will get right prompts.

like image 75
srinath samala Avatar answered Feb 06 '23 19:02

srinath samala


The answer above helped me out, thanks @srinath samala! Sharing why this worked for me in case it helps someone else.

I've been running Python on Windows 10 for a while, and months later installed Anaconda, which I don't think I did quite according to best practices. Windows machines can be annoying about proper PATH config etc...I probably need to uninstall and reinstall anaconda?

In any case, using the F1 key and Python:Select to point VS code toward which Python.exe file was being used made the difference here. Apparently using pip install in a windows bash session might make those packages available for one environment v the other? I'm sure this has something to do with my own (currently janky) directory structure, but VS code defaulted to Python's original home, and I got the import error. By selecting anaconda's version it found the package. Hope this helps someone else!

like image 37
Union In Design Avatar answered Feb 06 '23 17:02

Union In Design