【问题标题】:Installed scikit-learn doesn't work properly安装的 scikit-learn 无法正常工作
【发布时间】:2020-10-26 10:59:41
【问题描述】:

运行以下代码时出现此错误:

from sklearn.decomposition import LatentDirichletAllocation

ImportError:无法从部分初始化的模块“sklearn”导入名称“__check_build”(很可能是由于循环导入)。

当我检查pip freeze scikit-learn 已安装时。 另外,我尝试卸载并重新安装 sklearn,现在我得到了一个不同的错误:

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'

【问题讨论】:

  • @SamMason 已经尝试了所有这些。仍然无法正常工作
  • 使用virtualenvconda 环境,然后安装sklearn
  • @bigbounty 我正在使用 env 安装
  • Windows 是否还有 255 个字符的路径限制?如果是这种情况,可能值得尝试使用涉及较短路径的东西进行安装

标签: python python-3.x scikit-learn pip sklearn-pandas


【解决方案1】:

根据https://scikit-learn.org/stable/install.html

如果 Python 安装在嵌套位置(例如用户主目录下的 AppData 文件夹结构),则可能会出现 pip 在达到 Windows 的默认路径大小限制时无法安装包的情况,例如:

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

在这种情况下,可以使用 regedit 工具解除 Windows 注册表中的限制:

  1. 在 Windows 开始菜单中键入“regedit”以启动 regedit。

  2. 转到Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem 键。

  3. 编辑该键的 LongPathsEnabled 属性的值并将其设置为 1。

  4. 重新安装 scikit-learn(忽略之前损坏的安装):

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

【讨论】:

  • 将其更改为 1 并按照上述运行 pip 命令。重新启动 shell 后它工作了
猜你喜欢
  • 2022-01-17
  • 2020-09-11
  • 2014-04-30
  • 2021-01-17
  • 2021-02-13
  • 2012-05-03
  • 2021-07-20
  • 2018-12-21
  • 1970-01-01
相关资源
最近更新 更多