I try to install scikit-learn==1.2.2 for the django project and I got this error.
Collecting scikit-learn==1.2.2
Using cached scikit-learn-1.2.2.tar.gz (7.3 MB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... error
error: subprocess-exited-with-error
× Preparing metadata (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [36 lines of output]
Partial import of sklearn during the build process.
Traceback (most recent call last):
File "D:Group Project BackendPredictionenvLibsite-packagespip_vendorpyproject_hooks_in_process_in_process.py", line 353, in <module>
main()
File "D:Group Project BackendPredictionenvLibsite-packagespip_vendorpyproject_hooks_in_process_in_process.py", line 335, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:Group Project BackendPredictionenvLibsite-packagespip_vendorpyproject_hooks_in_process_in_process.py", line 149, in prepare_metadata_for_build_wheel
return hook(metadata_directory, config_settings)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:UsersASUSAppDataLocalTemppip-build-env-_ej3exweoverlayLibsite-packagessetuptoolsbuild_meta.py", line 366, in prepare_metadata_for_build_wheel
self.run_setup()
File "C:UsersASUSAppDataLocalTemppip-build-env-_ej3exweoverlayLibsite-packagessetuptoolsbuild_meta.py", line 487, in run_setup
super().run_setup(setup_script=setup_script)
File "C:UsersASUSAppDataLocalTemppip-build-env-_ej3exweoverlayLibsite-packagessetuptoolsbuild_meta.py", line 311, in run_setup
exec(code, locals())
File "<string>", line 669, in <module>
File "<string>", line 663, in setup_package
File "<string>", line 597, in configure_extension_modules
File "C:UsersASUSAppDataLocalTemppip-install-xv622fd3scikit-learn_6df30b226b524d1caf236a6b94005795sklearn_build_utils__init__.py", line 47, in cythonize_extensions
basic_check_build()
File "C:UsersASUSAppDataLocalTemppip-install-xv622fd3scikit-learn_6df30b226b524d1caf236a6b94005795sklearn_build_utilspre_build_helpers.py", line 82, in basic_check_build
compile_test_program(code)
File "C:UsersASUSAppDataLocalTemppip-install-xv622fd3scikit-learn_6df30b226b524d1caf236a6b94005795sklearn_build_utilspre_build_helpers.py", line 38, in compile_test_program
ccompiler.compile(
File "C:UsersASUSAppDataLocalTemppip-build-env-_ej3exweoverlayLibsite-packagessetuptools_distutils_msvccompiler.py", line 343, in compile
self.initialize()
File "C:UsersASUSAppDataLocalTemppip-build-env-_ej3exweoverlayLibsite-packagessetuptools_distutils_msvccompiler.py", line 253, in initialize
vc_env = _get_vc_env(plat_spec)
^^^^^^^^^^^^^^^^^^^^^^
File "C:UsersASUSAppDataLocalTemppip-build-env-_ej3exweoverlayLibsite-packagessetuptoolsmsvc.py", line 230, in msvc14_get_vc_env
return _msvc14_get_vc_env(plat_spec)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:UsersASUSAppDataLocalTemppip-build-env-_ej3exweoverlayLibsite-packagessetuptoolsmsvc.py", line 187, 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: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
`
I am using pyhton 3.12.2 in my windows machine. I am building career prediction website using React and django.I use vscode as my IDE. I train a model using google collab and it is used version 1.2.2 of the scikit-learn. I can install other packages like Django,djangorestframework but can’t install scikit-learn.
I’m installing everything in virtual environment.
2
Answers
The reason for the issue you encountered is that building the scikit-learn package from source requires Microsoft Visual C++ 14.0 or higher. Installing the required build tools is the first step towards fixing this problem. Here’s how to do it:
Install Microsoft C++ Build Tools : link
Update pip and setuptool.
pip install –upgrade pip setuptools
Install scikit-learn
pip install scikit-learn==1.2.2
The first version that provides wheels for Python 3.12 is scikit-learn 1.4.0. See https://pypi.org/project/scikit-learn/1.4.0/#files . So do not use old version, use a newer one. Either
pip install scikit-learn==1.4.2
or simplypip install scikit-learn
for the latest one (currently 1.5).Version 1.2.2 provides wheels up to Python 3.11. If you want to use 1.2.2 use older Python. Downgrade to Python 3.11.