Search code examples
pythonpython-3.xscikit-learnpipsklearn-pandas

Installed scikit-learn doesn't work properly


I am getting this error when I run the following code:

from sklearn.decomposition import LatentDirichletAllocation

ImportError: cannot import name '__check_build' from partially initialized module 'sklearn' (most likely due to a circular import).

When I check pip freeze scikit-learn is installed. Also,I tried to uninstall and reinstall sklearn,now I am getting a different error:

ERROR: Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: 'C:\\Users\\<user>\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python38\\site-packages\\sklearn\\datasets\\tests\\data\\openml\\292\\api-v1-json-data-list-data_name-australian-limit-2-data_version-1-status-deactivated.json.gz'

Solution

  • According to https://scikit-learn.org/stable/install.html

    It can happen that pip fails to install packages when reaching the default path size limit of Windows if Python is installed in a nested location such as the AppData folder structure under the user home directory, for instance:

    C:\Users\username>C:\Users\username\AppData\Local\Microsoft\WindowsApps\python.exe -m pip install scikit-learn
    Collecting scikit-learn
    ...
    Installing collected packages: scikit-learn
    ERROR: Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: 'C:\\Users\\username\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python37\\site-packages\\sklearn\\datasets\\tests\\data\\openml\\292\\api-v1-json-data-list-data_name-australian-limit-2-data_version-1-status-deactivated.json.gz
    

    In this case it is possible to lift that limit in the Windows registry by using the regedit tool:

    1. Type “regedit” in the Windows start menu to launch regedit.

    2. Go to the Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem key.

    3. Edit the value of the LongPathsEnabled property of that key and set it to 1.

    4. Reinstall scikit-learn (ignoring the previous broken installation):

    pip install --exists-action=i scikit-learn