Windows10でscikit-learnをcmdでインストールをしようとするとエラーが出てきてしまいます。
pip install scikit-learn
上のコードでインストール
エラー内容
ERROR: Command errored out with exit status 1: command: 'C:\Users\2210046\AppData\Local\Programs\Python\Python310\python.exe' 'C:\Users\2210046\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py' prepare_metadata_for_build_wheel 'C:\Users\2210046\AppData\Local\Temp\tmpvh99d_9t' cwd: C:\Users\2210046\AppData\Local\Temp\pip-install-k6be762b\scikit-learn_80a807f6ede9465182534d5061ac2838 Complete output (46 lines): 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:\Users\2210046\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 363, in <module> main() File "C:\Users\2210046\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 345, in main json_out['return_val'] = hook(**hook_input['kwargs']) File "C:\Users\2210046\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 164, in prepare_metadata_for_build_wheel return hook(metadata_directory, config_settings) File "C:\Users\2210046\AppData\Local\Temp\pip-build-env-op27i42_\overlay\Lib\site-packages\setuptools\build_meta.py", line 174, in prepare_metadata_for_build_wheel self.run_setup() File "C:\Users\2210046\AppData\Local\Temp\pip-build-env-op27i42_\overlay\Lib\site-packages\setuptools\build_meta.py", line 267, in run_setup super(_BuildMetaLegacyBackend, File "C:\Users\2210046\AppData\Local\Temp\pip-build-env-op27i42_\overlay\Lib\site-packages\setuptools\build_meta.py", line 158, in run_setup exec(compile(code, __file__, 'exec'), locals()) File "setup.py", line 319, in <module> setup_package() File "setup.py", line 315, in setup_package setup(**metadata) File "C:\Users\2210046\AppData\Local\Temp\pip-build-env-op27i42_\overlay\Lib\site-packages\numpy\distutils\core.py", line 135, in setup config = configuration() File "setup.py", line 201, in configuration config.add_subpackage("sklearn") File "C:\Users\2210046\AppData\Local\Temp\pip-build-env-op27i42_\overlay\Lib\site-packages\numpy\distutils\misc_util.py", line 1016, in add_subpackage config_list = self.get_subpackage(subpackage_name, subpackage_path, File "C:\Users\2210046\AppData\Local\Temp\pip-build-env-op27i42_\overlay\Lib\site-packages\numpy\distutils\misc_util.py", line 982, in get_subpackage config = self._get_configuration_from_setup_py( File "C:\Users\2210046\AppData\Local\Temp\pip-build-env-op27i42_\overlay\Lib\site-packages\numpy\distutils\misc_util.py", line 924, in _get_configuration_from_setup_py config = setup_module.configuration(*args) File "sklearn\setup.py", line 85, in configuration cythonize_extensions(top_path, config) File "C:\Users\2210046\AppData\Local\Temp\pip-install-k6be762b\scikit-learn_80a807f6ede9465182534d5061ac2838\sklearn\_build_utils\__init__.py", line 47, in cythonize_extensions basic_check_build() File "C:\Users\2210046\AppData\Local\Temp\pip-install-k6be762b\scikit-learn_80a807f6ede9465182534d5061ac2838\sklearn\_build_utils\pre_build_helpers.py", line 113, in basic_check_build compile_test_program(code) File "C:\Users\2210046\AppData\Local\Temp\pip-install-k6be762b\scikit-learn_80a807f6ede9465182534d5061ac2838\sklearn\_build_utils\pre_build_helpers.py", line 70, in compile_test_program ccompiler.compile( File "C:\Users\2210046\AppData\Local\Programs\Python\Python310\lib\distutils\_msvccompiler.py", line 323, in compile self.initialize() File "C:\Users\2210046\AppData\Local\Programs\Python\Python310\lib\distutils\_msvccompiler.py", line 220, in initialize vc_env = _get_vc_env(plat_spec) File "C:\Users\2210046\AppData\Local\Temp\pip-build-env-op27i42_\overlay\Lib\site-packages\setuptools\msvc.py", line 316, in msvc14_get_vc_env return _msvc14_get_vc_env(plat_spec) File "C:\Users\2210046\AppData\Local\Temp\pip-build-env-op27i42_\overlay\Lib\site-packages\setuptools\msvc.py", line 270, in _msvc14_get_vc_env raise distutils.errors.DistutilsPlatformError( 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/
> command: 'C:\Users\2210046\AppData\Local\Programs\Python\Python310\python.exe'
から、Python 3.10を使ってると想像して、以下書きます
https://pypi.org/project/scikit-learn/#files
を見ると、Python 3.10用のwheelは用意されてません
(ファイル名の「cp数字」の「数字」がPythonのバージョンを表す)
なので、pipはソース(scikit-learn-1.0.1.tar.gz)からコンパイルしようとします
> Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
コンパイルに必要なコンパイラが無いよ、って言ってます
どうしてもPython 3.10を使わないといけない理由が無いのなら、wheelが用意されてる3.7〜3.9のどれかを使うことをお勧めします
【追記】
二つ以上のバージョンのPythonを同時に別個にパソコンにインストールするのはトラブルの元になるので、もしPython 3.7〜3.9を入れる場合は、3.10を残さないといけない理由が特に無いなら、3.10は削除してしまうことをお勧めします
ありがとうございます。解決しました