I want to use sklearn.neighbors but whenever I try importing sklearn or sklearn.neighbors I get the same error message.
I am using the following versions:
Windows: 10.0.19044
Python: 3.7.3
Scikit-learn: 1.0.2
Numpy: 1.21.6
Scipy: 1.7.3
I am trying to import it into FreeCAD 0.20.1 using the integrated python console. I first sys.path.append() to the path of the sklearn installation, then try to import sklearn.
Error message in question:
>>> import sklearn
Traceback (most recent call last):
File "C:\RoboDK\Python37\Lib\site-packages\sklearn\__check_build\__init__.py", line 48, in <module>
from ._check_build import check_build # noqa
File "C:\Program Files\FreeCAD 0.20\bin\Lib\site-packages\shiboken2\files.dir\shibokensupport\__feature__.py", line 142, in _import
return original_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'sklearn.__check_build._check_build'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files\FreeCAD 0.20\bin\Lib\site-packages\shiboken2\files.dir\shibokensupport\__feature__.py", line 142, in _import
return original_import(name, *args, **kwargs)
File "C:\RoboDK\Python37\Lib\site-packages\sklearn\__init__.py", line 81, in <module>
from . import __check_build # noqa: F401
File "C:\Program Files\FreeCAD 0.20\bin\Lib\site-packages\shiboken2\files.dir\shibokensupport\__feature__.py", line 142, in _import
return original_import(name, *args, **kwargs)
File "C:\RoboDK\Python37\Lib\site-packages\sklearn\__check_build\__init__.py", line 50, in <module>
raise_build_error(e)
File "C:\RoboDK\Python37\Lib\site-packages\sklearn\__check_build\__init__.py", line 31, in raise_build_error
raise ImportError(
ImportError: No module named 'sklearn.__check_build._check_build'
___________________________________________________________________________
Contents of C:\RoboDK\Python37\Lib\site-packages\sklearn\__check_build:
setup.py _check_build.cp37-win_amd64.pyd__init__.py
__pycache__
___________________________________________________________________________
It seems that scikit-learn has not been built correctly.
If you have installed scikit-learn from source, please do not forget
to build the package before using it: run `python setup.py install` or
`make` in the source directory.
If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform.
After several attempts of uninstalling, reinstalling and searching for solutions I still get the same error message with and without using administrator access. I also tried older versions of scikit-learn without any luck.
I used pip install -U scikit-learn to install the package.
I also checked the recommended commands:
python -m pip show scikit-learn # to see which version and where scikit-learn is installed
python -m pip freeze # to see all packages installed in the active virtualenv
python -c "import sklearn; sklearn.show_versions()"
And all of them list the installed version of scikit-learn as 1.0.2, so I guess that is working fine.
SOLVED:
FreeCAD used an own installation of Python 3.8, while I installed the package for the system default version 3.7. After I used py -3.8 -m pip install scikit-learn==1.2.2 it worked fine! Thanks for your help anyway!