省流:换python3.8及以下
查到有的资料[1]说
pip install scikit-learn==0.22.2.post1
于是
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "C:\Users\Administrator\AppData\Local\Temp\pip-install-0qy5frl9\scikit-learn_51d26eba6ac5440abca106d74b8b3908\setup.py", line 303, in <module>
setup_package()
File "C:\Users\Administrator\AppData\Local\Temp\pip-install-0qy5frl9\scikit-learn_51d26eba6ac5440abca106d74b8b3908\setup.py", line 299, in setup_package
setup(**metadata)
File "D:\miniconda3\envs\moba_ai\lib\site-packages\numpy\distutils\core.py", line 136, in setup
config = configuration()
File "C:\Users\Administrator\AppData\Local\Temp\pip-install-0qy5frl9\scikit-learn_51d26eba6ac5440abca106d74b8b3908\setup.py", line 180, in configuration
_check_cython_version()
File "C:\Users\Administrator\AppData\Local\Temp\pip-install-0qy5frl9\scikit-learn_51d26eba6ac5440abca106d74b8b3908\sklearn\_build_utils\__init__.py", line 35, in _check_cython_version
raise ModuleNotFoundError(message)
ModuleNotFoundError: Please install Cython with a version >= 0.28.5 in order to build a scikit-learn from source.
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for scikit-learn
Running setup.py clean for scikit-learn
Failed to build scikit-learn
ERROR: Could not build wheels for scikit-learn, which is required to install pyproject.toml-based projects
可以都看到,没有Cython >= 0.28.5
,因此
pip install Cython
INFO: No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "C:\Users\Administrator\AppData\Local\Temp\pip-install-kbdsij39\scikit-learn_79d25be938d34b5f91962c28958153a1\setup.py", line 303, in <module>
setup_package()
File "C:\Users\Administrator\AppData\Local\Temp\pip-install-kbdsij39\scikit-learn_79d25be938d34b5f91962c28958153a1\setup.py", line 299, in setup_package
setup(**metadata)
File "D:\miniconda3\envs\moba_ai\lib\site-packages\numpy\distutils\core.py", line 136, in setup
config = configuration()
File "C:\Users\Administrator\AppData\Local\Temp\pip-install-kbdsij39\scikit-learn_79d25be938d34b5f91962c28958153a1\setup.py", line 182, in configuration
config.add_subpackage('sklearn')
File "D:\miniconda3\envs\moba_ai\lib\site-packages\numpy\distutils\misc_util.py", line 1050, in add_subpackage
config_list = self.get_subpackage(subpackage_name, subpackage_path,
File "D:\miniconda3\envs\moba_ai\lib\site-packages\numpy\distutils\misc_util.py", line 1016, in get_subpackage
config = self._get_configuration_from_setup_py(
File "D:\miniconda3\envs\moba_ai\lib\site-packages\numpy\distutils\misc_util.py", line 958, in _get_configuration_from_setup_py
config = setup_module.configuration(*args)
File "C:\Users\Administrator\AppData\Local\Temp\pip-install-kbdsij39\scikit-learn_79d25be938d34b5f91962c28958153a1\sklearn\setup.py", line 86, in configuration
cythonize_extensions(top_path, config)
File "C:\Users\Administrator\AppData\Local\Temp\pip-install-kbdsij39\scikit-learn_79d25be938d34b5f91962c28958153a1\sklearn\_build_utils\__init__.py", line 50, in cythonize_extensions
basic_check_build()
File "C:\Users\Administrator\AppData\Local\Temp\pip-install-kbdsij39\scikit-learn_79d25be938d34b5f91962c28958153a1\sklearn\_build_utils\pre_build_helpers.py", line 70, in basic_check_build
compile_test_program(code)
File "C:\Users\Administrator\AppData\Local\Temp\pip-install-kbdsij39\scikit-learn_79d25be938d34b5f91962c28958153a1\sklearn\_build_utils\pre_build_helpers.py", line 39, in compile_test_program
ccompiler.compile(['test_program.c'], output_dir='objects',
File "D:\miniconda3\envs\moba_ai\lib\site-packages\setuptools\_distutils\_msvccompiler.py", line 343, in compile
self.initialize()
File "D:\miniconda3\envs\moba_ai\lib\site-packages\setuptools\_distutils\_msvccompiler.py", line 253, in initialize
vc_env = _get_vc_env(plat_spec)
File "D:\miniconda3\envs\moba_ai\lib\site-packages\setuptools\msvc.py", line 233, in msvc14_get_vc_env
return _msvc14_get_vc_env(plat_spec)
File "D:\miniconda3\envs\moba_ai\lib\site-packages\setuptools\msvc.py", line 190, in _msvc14_get_vc_env
raise distutils.errors.DistutilsPlatformError("Unable to find vcvarsall.bat")
distutils.errors.DistutilsPlatformError: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for scikit-learn
Running setup.py clean for scikit-learn
Failed to build scikit-learn
ERROR: Could not build wheels for scikit-learn, which is required to install pyproject.toml-based projects
进入这里
https://visualstudio.microsoft.com/zh-hans/visual-cpp-build-tools/
打开cmd[2]
vs_buildtools.exe --norestart --passive --downloadThenInstall --includeRecommended --add Microsoft.VisualStudio.Workload.NativeDesktop --add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Workload.MSBuildTools
会跳出来这个
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "C:\Users\Administrator\AppData\Local\Temp\pip-install-ac1o3a7y\scikit-learn_e68a25e9e3074acbafa5de17ed8344eb\setup.py", line 303, in <module>
setup_package()
File "C:\Users\Administrator\AppData\Local\Temp\pip-install-ac1o3a7y\scikit-learn_e68a25e9e3074acbafa5de17ed8344eb\setup.py", line 299, in setup_package
setup(**metadata)
File "D:\miniconda3\envs\moba_ai\lib\site-packages\numpy\distutils\core.py", line 136, in setup
config = configuration()
File "C:\Users\Administrator\AppData\Local\Temp\pip-install-ac1o3a7y\scikit-learn_e68a25e9e3074acbafa5de17ed8344eb\setup.py", line 182, in configuration
config.add_subpackage('sklearn')
File "D:\miniconda3\envs\moba_ai\lib\site-packages\numpy\distutils\misc_util.py", line 1050, in add_subpackage
config_list = self.get_subpackage(subpackage_name, subpackage_path,
File "D:\miniconda3\envs\moba_ai\lib\site-packages\numpy\distutils\misc_util.py", line 1016, in get_subpackage
config = self._get_configuration_from_setup_py(
File "D:\miniconda3\envs\moba_ai\lib\site-packages\numpy\distutils\misc_util.py", line 958, in _get_configuration_from_setup_py
config = setup_module.configuration(*args)
File "C:\Users\Administrator\AppData\Local\Temp\pip-install-ac1o3a7y\scikit-learn_e68a25e9e3074acbafa5de17ed8344eb\sklearn\setup.py", line 86, in configuration
cythonize_extensions(top_path, config)
File "C:\Users\Administrator\AppData\Local\Temp\pip-install-ac1o3a7y\scikit-learn_e68a25e9e3074acbafa5de17ed8344eb\sklearn\_build_utils\__init__.py", line 75, in cythonize_extensions
config.ext_modules = cythonize(
File "D:\miniconda3\envs\moba_ai\lib\site-packages\Cython\Build\Dependencies.py", line 1145, in cythonize
result.get(99999) # seconds
File "D:\miniconda3\envs\moba_ai\lib\multiprocessing\pool.py", line 771, in get
raise self._value
Cython.Compiler.Errors.CompileError: sklearn\svm\_liblinear.pyx
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for scikit-learn
Running setup.py clean for scikit-learn
Failed to build scikit-learn
ERROR: Could not build wheels for scikit-learn, which is required to install pyproject.toml-based projects
nmdwsm
经过一些玄学尝试,最后发现,似乎和版本有问题
python3.6.10,和python3.8.10是可以的(目测3.7也可以)
python3.9.0和python3.10.0不行
创建环境
conda create n test1 python==3.8.10
安装
pip install numpy cython
pip install scikit-learn==0.22.2.post1
终于可以了
参考:
[1] https://stackoverflow.com/questions/61177448/no-module-named-sklearn-neural-network-multilayer-perceptron
[2] https://stackoverflow.com/questions/64261546/how-to-solve-error-microsoft-visual-c-14-0-or-greater-is-required-when-inst