无法在我的窗口中使用 Jupyter Notebook 从 Git 安装 scikit-learn



我正在尝试导入sklearn.metrics.multilabel_confusion_matrix,但由于它不在普通包中,我试图做的是使用 Jupyter 笔记本在我的 Windows 中使用!pip install git+http://github.com/scikit-learn/scikit-learn.git安装它。我也使用了命令提示符,但发生了同样的问题。但是当我这样做时会弹出一个错误,如下所示

它说的是与"失败的scikit-learn构建轮子"有关的内容 由于环境错误,无法安装软件包:">

在下面显示了完整的对话。 请帮忙!!

!pip install git+http://github.com/scikit-learn/scikit-learn.git
Collecting git+http://github.com/scikit-learn/scikit-learn.git
Cloning http://github.com/scikit-learn/scikit-learn.git to c:usersintelappdatalocaltemppip-req-build-bg_zxcrm
Requirement already satisfied: numpy>=1.11.0 in c:programdataanaconda3libsite-packages (from scikit-learn==0.22.dev0) (1.15.4)
Requirement already satisfied: scipy>=0.17.0 in c:programdataanaconda3libsite-packages (from scikit-learn==0.22.dev0) (1.1.0)
Requirement already satisfied: joblib>=0.11 in c:programdataanaconda3libsite-packages (from scikit-learn==0.22.dev0) (0.14.0)
Building wheels for collected packages: scikit-learn
Running setup.py bdist_wheel for scikit-learn: started
Running setup.py bdist_wheel for scikit-learn: finished with status 'error'
Complete output from command C:PROGRAMDATAANACONDA3python.exe -u -c "import setuptools, tokenize;__file__='C:\Users\INTEL\AppData\Local\Temp\pip-req-build-bg_zxcrm\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('rn', 'n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d C:UsersINTELAppDataLocalTemppip-wheel-vp_d4jnx --python-tag cp37:
Partial import of sklearn during the build process.
No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
Traceback (most recent call last):
File "C:PROGRAMDATAANACONDA3libsite-packagessetuptoolsmsvc.py", line 489, in _find_latest_available_vc_ver
return self.find_available_vc_vers()[-1]
IndexError: list index out of range
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:UsersINTELAppDataLocalTemppip-req-build-bg_zxcrmsetup.py", line 290, in <module>
setup_package()
File "C:UsersINTELAppDataLocalTemppip-req-build-bg_zxcrmsetup.py", line 286, in setup_package
setup(**metadata)
File "C:PROGRAMDATAANACONDA3libsite-packagesnumpydistutilscore.py", line 135, in setup
config = configuration()
File "C:UsersINTELAppDataLocalTemppip-req-build-bg_zxcrmsetup.py", line 174, in configuration
config.add_subpackage('sklearn')
File "C:PROGRAMDATAANACONDA3libsite-packagesnumpydistutilsmisc_util.py", line 1037, in add_subpackage
caller_level = 2)
File "C:PROGRAMDATAANACONDA3libsite-packagesnumpydistutilsmisc_util.py", line 1006, in get_subpackage
caller_level = caller_level + 1)
File "C:PROGRAMDATAANACONDA3libsite-packagesnumpydistutilsmisc_util.py", line 943, in _get_configuration_from_setup_py
config = setup_module.configuration(*args)
File "sklearnsetup.py", line 81, in configuration
maybe_cythonize_extensions(top_path, config)
File "C:UsersINTELAppDataLocalTemppip-req-build-bg_zxcrmsklearn_build_utils__init__.py", line 43, in maybe_cythonize_extensions
with_openmp = check_openmp_support()
File "C:UsersINTELAppDataLocalTemppip-req-build-bg_zxcrmsklearn_build_utilsopenmp_helpers.py", line 84, in check_openmp_support
extra_postargs=openmp_flags)
File "C:PROGRAMDATAANACONDA3libdistutils_msvccompiler.py", line 345, in compile
self.initialize()
File "C:PROGRAMDATAANACONDA3libdistutils_msvccompiler.py", line 238, in initialize
vc_env = _get_vc_env(plat_spec)
File "C:PROGRAMDATAANACONDA3libsite-packagessetuptoolsmsvc.py", line 185, in msvc14_get_vc_env
return EnvironmentInfo(plat_spec, vc_min_ver=14.0).return_env()
File "C:PROGRAMDATAANACONDA3libsite-packagessetuptoolsmsvc.py", line 843, in __init__
self.si = SystemInfo(self.ri, vc_ver)
File "C:PROGRAMDATAANACONDA3libsite-packagessetuptoolsmsvc.py", line 485, in __init__
self.vc_ver = vc_ver or self._find_latest_available_vc_ver()
File "C:PROGRAMDATAANACONDA3libsite-packagessetuptoolsmsvc.py", line 492, in _find_latest_available_vc_ver
raise distutils.errors.DistutilsPlatformError(err)
distutils.errors.DistutilsPlatformError: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": https://visualstudio.microsoft.com/downloads/
----------------------------------------
Running setup.py clean for scikit-learn
Failed to build scikit-learn
Installing collected packages: scikit-learn
Found existing installation: scikit-learn 0.20.1
Uninstalling scikit-learn-0.20.1:
Failed building wheel for scikit-learn
Could not install packages due to an EnvironmentError: [WinError 5] Access is denied: 'c:\programdata\anaconda3\lib\site-packages\scikit_learn-0.20.1-py3.7.egg-info\dependency_links.txt'
Consider using the `--user` option or check the permissions.

在收到类似的错误后,我能够按照官方网站 https://scikit-learn.org/stable/install.html 的说明安装scikit-learn

由 Windows 上的文件路径长度限制引起的错误

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

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 注册表中解除该限制:

在Windows开始菜单中键入"regedit"以启动regedit。

转到ComputerHKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlFileSystem键。

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

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

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

最新更新