2

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'
Roshin Raphel
  • 2,612
  • 4
  • 22
  • 40
Sri Test
  • 389
  • 1
  • 4
  • 21
  • 1
    Does this answer your question? [ImportError in importing from sklearn: cannot import name check\_build](https://stackoverflow.com/questions/15274696/importerror-in-importing-from-sklearn-cannot-import-name-check-build) – Sam Mason Jul 06 '20 at 10:26
  • @SamMason already tried all of them.Doesn't work still – Sri Test Jul 06 '20 at 10:28
  • Use `virtualenv` or `conda` env and then install `sklearn` – bigbounty Jul 06 '20 at 10:33
  • @bigbounty I am installing using env already – Sri Test Jul 06 '20 at 10:35
  • does windows still have a 255 char path limit? might be worth trying to install using something that involves shorter paths if that's the case – Sam Mason Jul 06 '20 at 10:38

1 Answers1

12

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

bigbounty
  • 16,526
  • 5
  • 37
  • 65