我一直在尝试通过命令安装 scikit learn
pip install scikit-learn
,但它向我显示了下面给出的错误。
PS:
- Python 版本 3.8.5
- pip 版本 22.3
错误显示:
Collecting scikit-learn
Using cached scikit-learn-1.1.3.tar.gz (7.0 MB)
Installing build dependencies ... error
error: subprocess-exited-with-error
× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> [96 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<60.0
Using cached setuptools-59.8.0-py3-none-any.whl (952 kB)
Collecting wheel
Using cached wheel-0.37.1-py2.py3-none-any.whl (35 kB)
Collecting Cython>=0.28.5
Using cached Cython-0.29.32-py2.py3-none-any.whl (986 kB)
Collecting oldest-supported-numpy
Using cached oldest_supported_numpy-2022.8.16-py3-none-any.whl (3.9 kB)
Collecting scipy>=1.3.2
Using cached scipy-1.9.3.tar.gz (42.1 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 'error'
error: subprocess-exited-with-error
Getting requirements to build wheel did not run successfully.
exit code: 1
[64 lines of output]
The Meson build system
Version: 0.63.3
Source dir: C:\Users\manju\AppData\Local\Temp\pip-install-1t0wentg\scipy_8ed1046c49a04dd98aabab84e6319b67
Build dir: C:\Users\manju\AppData\Local\Temp\pip-install-1t0wentg\scipy_8ed1046c49a04dd98aabab84e6319b67\.mesonpy-nddxhmy3\build
Build type: native build
Project name: SciPy
Project version: 1.9.3
C compiler for the host machine: gcc (gcc 9.2.0 "gcc (MinGW.org GCC Build-2) 9.2.0")
C linker for the host machine: gcc ld.bfd 2.32
C++ compiler for the host machine: c++ (gcc 9.2.0 "c++ (MinGW.org GCC Build-2) 9.2.0")
C++ linker for the host machine: c++ ld.bfd 2.32
Host machine cpu family: x86
Host machine cpu: x86
Compiler for C supports arguments -Wno-unused-but-set-variable: YES
Compiler for C supports arguments -Wno-unused-but-set-variable: YES (cached)
Compiler for C supports arguments -Wno-unused-function: YES
Compiler for C supports arguments -Wno-conversion: YES
Compiler for C supports arguments -Wno-misleading-indentation: YES
Compiler for C supports arguments -Wno-incompatible-pointer-types: YES
Library m found: YES
..\..\meson.build:57:0: ERROR: Unknown compiler(s): [['ifort'], ['gfortran'], ['flang'], ['pgfortran'], ['g95']]
The following exception(s) were encountered:
Running `ifort --version` gave "[WinError 2] The system cannot find the file specified"
Running `ifort -V` gave "[WinError 2] The system cannot find the file specified"
Running `gfortran --version` gave "[WinError 2] The system cannot find the file specified"
Running `gfortran -V` gave "[WinError 2] The system cannot find the file specified"
Running `flang --version` gave "[WinError 2] The system cannot find the file specified"
Running `flang -V` gave "[WinError 2] The system cannot find the file specified"
Running `pgfortran --version` gave "[WinError 2] The system cannot find the file specified"
Running `pgfortran -V` gave "[WinError 2] The system cannot find the file specified"
Running `g95 --version` gave "[WinError 2] The system cannot find the file specified"
Running `g95 -V` gave "[WinError 2] The system cannot find the file specified"
A full log can be found at C:\Users\manju\AppData\Local\Temp\pip-install-1t0wentg\scipy_8ed1046c49a04dd98aabab84e6319b67\.mesonpy-nddxhmy3\build\meson-logs\meson-log.txt
+ meson setup --native-file=C:\Users\manju\AppData\Local\Temp\pip-install-1t0wentg\scipy_8ed1046c49a04dd98aabab84e6319b67\.mesonpy-native-file.ini -Ddebug=false -Doptimization=2 --prefix=c:\users\manju\appdata\local\programs\python\python38-32 C:\Users\manju\AppData\Local\Temp\pip-install-1t0wentg\scipy_8ed1046c49a04dd98aabab84e6319b67 C:\Users\manju\AppData\Local\Temp\pip-install-1t0wentg\scipy_8ed1046c49a04dd98aabab84e6319b67\.mesonpy-nddxhmy3\build
Traceback (most recent call last):
File "C:\Users\manju\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 351, in <module>
main()
File "C:\Users\manju\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 333, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "C:\Users\manju\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 118, in get_requires_for_build_wheel
return hook(config_settings)
File "C:\Users\manju\AppData\Local\Temp\pip-build-env-8ril8k9h\overlay\Lib\site-packages\mesonpy\__init__.py", line 969, in get_requires_for_build_wheel
with _project(config_settings) as project:
File "c:\users\manju\appdata\local\programs\python\python38-32\lib\contextlib.py", line 113, in __enter__
return next(self.gen)
File "C:\Users\manju\AppData\Local\Temp\pip-build-env-8ril8k9h\overlay\Lib\site-packages\mesonpy\__init__.py", line 948, in _project
with Project.with_temp_working_dir(
File "c:\users\manju\appdata\local\programs\python\python38-32\lib\contextlib.py", line 113, in __enter__
return next(self.gen)
File "C:\Users\manju\AppData\Local\Temp\pip-build-env-8ril8k9h\overlay\Lib\site-packages\mesonpy\__init__.py", line 777, in with_temp_working_dir
yield cls(source_dir, tmpdir, build_dir)
File "C:\Users\manju\AppData\Local\Temp\pip-build-env-8ril8k9h\overlay\Lib\site-packages\mesonpy\__init__.py", line 682, in __init__
self._configure(reconfigure=bool(build_dir) and not native_file_mismatch)
File "C:\Users\manju\AppData\Local\Temp\pip-build-env-8ril8k9h\overlay\Lib\site-packages\mesonpy\__init__.py", line 713, in _configure
self._meson(
File "C:\Users\manju\AppData\Local\Temp\pip-build-env-8ril8k9h\overlay\Lib\site-packages\mesonpy\__init__.py", line 696, in _meson
return self._proc('meson', *args)
File "C:\Users\manju\AppData\Local\Temp\pip-build-env-8ril8k9h\overlay\Lib\site-packages\mesonpy\__init__.py", line 691, in _proc
subprocess.check_call(list(args))
File "c:\users\manju\appdata\local\programs\python\python38-32\lib\subprocess.py", line 364, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['meson', 'setup', '--native-file=C:\\Users\\manju\\AppData\\Local\\Temp\\pip-install-1t0wentg\\scipy_8ed1046c49a04dd98aabab84e6319b67\\.mesonpy-native-file.ini', '-Ddebug=false', '-Doptimization=2', '--prefix=c:\\users\\manju\\appdata\\local\\programs\\python\\python38-32', 'C:\\Users\\manju\\AppData\\Local\\Temp\\pip-install-1t0wentg\\scipy_8ed1046c49a04dd98aabab84e6319b67', 'C:\\Users\\manju\\AppData\\Local\\Temp\\pip-install-1t0wentg\\scipy_8ed1046c49a04dd98aabab84e6319b67\\.mesonpy-nddxhmy3\\build']' returned non-zero exit status 1.
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error
Getting requirements to build wheel 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.
[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.
安装 scikit-learn 时出现的错误与缺少 SciPy(安装 scikit-learn 的依赖项)构建轮子所需的 Fortran 编译器有关。
以下是解决此问题的方法:
1. 安装 Fortran 编译器:
- 对于 Windows:
- 最简单的方法是安装 MinGW-w64。你可以从 https://www.mingw-w64.org/ 下载。在安装过程中,请确保选择了正确的架构(32 位或 64 位),并包含了 Fortran 编译器(例如 gfortran)。
- 对于 macOS:
-
你可以使用 Homebrew 安装 gfortran:
brew install gcc
- 对于 Linux:
-
使用你的发行版的包管理器安装 gfortran。例如,在 Ubuntu/Debian 上:
sudo apt-get install gfortran
2. 将 Fortran 编译器添加到你的 PATH 环境变量:
- 确保 Fortran 编译器(例如 gfortran.exe)所在的目录在你的 PATH 环境变量中。这将允许 pip 找到编译器。
3. 升级 pip:
-
在某些情况下,过时的 pip 版本可能会导致问题。尝试升级 pip:
pip install --upgrade pip
4. 重新安装 scikit-learn:
-
完成上述步骤后,再次尝试安装 scikit-learn:
pip install scikit-learn
如果问题仍然存在,请尝试以下操作:
- 创建一个新的虚拟环境: 虚拟环境可以帮助你避免软件包之间的冲突。
- 使用预编译的轮子: 考虑从 https://www.lfd.uci.edu/~gohlke/pythonlibs/ 下载 SciPy 的预编译轮子,并使用 pip 手动安装。
-
升级 setuptools:
确保 setuptools 是最新的:
pip install --upgrade setuptools
这些步骤应该可以帮助你成功安装 scikit-learn。如果问题仍然存在,请提供你的操作系统以及有关你环境的更多信息,以便我提供更具体的帮助。
标签:python,installation,scikit-learn,pip,subprocess From: 74226688