Python 3.11(32位)安装Scikit-learn失败问题求助
问题:Python 3.11(32位)环境安装Scikit-learn失败
执行命令
(sklearn-venv) C:\Users\212552727>pip install -U scikit-learn
报错信息
Collecting scikit-learn Using cached scikit-learn-1.3.0.tar.gz (7.5 MB) Installing build dependencies ... error error: subprocess-exited-with-error × pip subprocess to install build dependencies did not run successfully. │ exit code: 1 ╰─> [61 lines of output] Ignoring numpy: markers 'python_version == "3.10" and platform_system == "Windows" and platform_python_implementation != "PyPy"' don't match your environment Collecting setuptools Obtaining dependency information for setuptools from https://files.pythonhosted.org/packages/4f/ab/0bcfebdfc3bfa8554b2b2c97a555569c4c1ebc74ea288741ea8326c51906/setuptools-68.1.2-py3-none-any.whl.metadata Using cached setuptools-68.1.2-py3-none-any.whl.metadata (6.2 kB) Collecting wheel Obtaining dependency information for wheel from https://files.pythonhosted.org/packages/28/f5/6955d7b3a5d71ce6bac104f9cf98c1b0513ad656cdaca8ea7d579196f771/wheel-0.41.1-py3-none-any.whl.metadata Using cached wheel-0.41.1-py3-none-any.whl.metadata (2.2 kB) Collecting Cython>=0.29.33 Obtaining dependency information for Cython>=0.29.33 from https://files.pythonhosted.org/packages/b3/a8/be1d37323992bf6e2bece09150ce8f8905216d1df8b70d459df6e2a79c5f/Cython-3.0.0-cp311-cp311-win32.whl.metadata Using cached Cython-3.0.0-cp311-cp311-win32.whl.metadata (3.2 kB) Collecting oldest-supported-numpy Obtaining dependency information for oldest-supported-numpy from https://files.pythonhosted.org/packages/94/9a/756fef9346e5ca2289cb70d73990b4c9f25446a885c1186cfb93a85e7da0/oldest_supported_numpy-2023.8.3-py3-none-any.whl.metadata Using cached oldest_supported_numpy-2023.8.3-py3-none-any.whl.metadata (9.5 kB) Collecting scipy>=1.5.0 Using cached scipy-1.11.2.tar.gz (56.0 MB) Installing build dependencies: started Installing build dependencies: finished with status 'done' Getting requirements to build wheel: started Getting requirements to build wheel: finished with status 'done' Installing backend dependencies: started Installing backend dependencies: finished with status 'done' Preparing metadata (pyproject.toml): started Preparing metadata (pyproject.toml): finished with status 'error' error: subprocess-exited-with-error Preparing metadata (pyproject.toml) did not run successfully. exit code: 1 [21 lines of output] + meson setup C:\Users\212552727\AppData\Local\Temp\pip-install-h64wkdxq\scipy_1a636eae7acb424b8b57aad910729f74 C:\Users\212552727\AppData\Local\Temp\pip-install-h64wkdxq\scipy_1a636eae7acb424b8b57aad910729f74\.mesonpy-361i6tyw\build -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md --native-file=C:\Users\212552727\AppData\Local\Temp\pip-install-h64wkdxq\scipy_1a636eae7acb424b8b57aad910729f74\.mesonpy-361i6tyw\build\meson-python-native-file.ini The Meson build system Version: 1.2.1 Source dir: C:\Users\212552727\AppData\Local\Temp\pip-install-h64wkdxq\scipy_1a636eae7acb424b8b57aad910729f74 Build dir: C:\Users\212552727\AppData\Local\Temp\pip-install-h64wkdxq\scipy_1a636eae7acb424b8b57aad910729f74\.mesonpy-361i6tyw\build Build type: native build Project name: SciPy Project version: 1.11.2 WARNING: Failed to activate VS environment: Could not find C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe ..\..\meson.build:1:0: ERROR: Unknown compiler(s): [['icl'], ['cl'], ['cc'], ['gcc'], ['clang'], ['clang-cl'], ['pgcc']] The following exception(s) were encountered: Running `icl ""` gave "[WinError 2] The system cannot find the file specified" Running `cl /?` gave "[WinError 2] The system cannot find the file specified" Running `cc --version` gave "[WinError 2] The system cannot find the file specified" Running `gcc --version` gave "[WinError 2] The system cannot find the file specified" Running `clang --version` gave "[WinError 2] The system cannot find the file specified" Running `clang-cl /?` gave "[WinError 2] The system cannot find the file specified" Running `pgcc --version` gave "[WinError 2] The system cannot find the file specified" A full log can be found at C:\Users\212552727\AppData\Local\Temp\pip-install-h64wkdxq\scipy_1a636eae7acb424b8b57aad910729f74\.mesonpy-361i6tyw\build\meson-logs\meson-log.txt [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. [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error × pip subprocess to install build dependencies did not run successfully. │ exit code: 1 ╰─> See above for output. note: This error originates from a subprocess, and is likely not a problem with pip.
核心原因
无法激活VS环境,找不到可用编译器,导致Scipy元数据生成失败,进而使Scikit-learn的构建依赖安装失败。
解决方案
- 安装Visual Studio Build Tools:
下载并安装Visual Studio Build Tools,勾选「桌面开发使用C++」工作负载,确保包含MSVC编译器、Windows SDK等核心组件。安装完成后重启终端,让环境变量生效。 - 使用预编译wheel包安装:
直接下载对应Python 3.11(32位)版本的scipy和scikit-learn预编译wheel文件,跳过编译步骤。执行以下命令安装:pip install scipy-1.11.2-cp311-cp311-win32.whl pip install scikit-learn-1.3.0-cp311-cp311-win32.whl - 验证安装结果:
安装完成后,运行以下代码确认成功:import sklearn print(sklearn.__version__)
内容的提问来源于stack exchange,提问作者Walter
相关产品推荐
相关产品推荐

