Search code examples
pythonscikit-learnpython-packaging

Cannot import a method from sklearn (using VSCode)


I'm using VSCode, and I import KDTree like this

from sklearn.neighbors import KDTree

while the KDTree stays in white(which means VSCode cannot find this method)

I'm using python3.8 on my Linux and 3.9 on my Mac

addtional info: I've installed sklearn, and I checked init.py file in sklearn.neighbors

It looks like this sklearn.neighbors init.py

Why the KDTree parts stays in white?


Solution

  • If KDTree is not highlighted in the expected color, it doesn't mean VS-Code could not find this method. It could just mean that you have not accessed this method yet in your program. Try creating a KDTree object, it should work as expected.

    Note that if you haven't installed "sklearn" yet, you would need to install it first before using sklearn.KDTree.