执行pip安装依赖时遇Fortran编译器未识别错误求助
问题描述
执行pip install -r requirements_versions.txt安装Python依赖时,始终遇到Fortran编译器相关错误,尝试从官网安装编译器后问题仍未解决。
具体错误信息
× Preparing metadata (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [37 lines of output] + meson setup C:\Users\bagda\AppData\Local\Temp\pip-install-cyk95ir8\scipy_3e9529a1d9cd407a96011bdcdb5c5cd6 C:\Users\bagda\AppData\Local\Temp\pip-install-cyk95ir8\scipy_3e9529a1d9cd407a96011bdcdb5c5cd6\.mesonpy-90rqinq2 -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md --native-file=C:\Users\bagda\AppData\Local\Temp\pip-install-cyk95ir8\scipy_3e9529a1d9cd407a96011bdcdb5c5cd6\.mesonpy-90rqinq2\meson-python-native-file.ini The Meson build system Version: 1.3.0 Source dir: C:\Users\bagda\AppData\Local\Temp\pip-install-cyk95ir8\scipy_3e9529a1d9cd407a96011bdcdb5c5cd6 Build dir: C:\Users\bagda\AppData\Local\Temp\pip-install-cyk95ir8\scipy_3e9529a1d9cd407a96011bdcdb5c5cd6\.mesonpy-90rqinq2 Build type: native build Project name: SciPy Project version: 1.9.3 Activating VS 17.8.2 C compiler for the host machine: cl (msvc 19.38.33130 "Microsoft (R) C/C++ Optimizing Compiler Version 19.38.33130 for x64") C linker for the host machine: link link 14.38.33130.0 C++ compiler for the host machine: cl (msvc 19.38.33130 "Microsoft (R) C/C++ Optimizing Compiler Version 19.38.33130 for x64") C++ linker for the host machine: link link 14.38.33130.0 Host machine cpu family: x86_64 Host machine cpu: x86_64 Compiler for C supports arguments -Wno-unused-but-set-variable: NO Compiler for C supports arguments -Wno-unused-but-set-variable: NO (cached) Compiler for C supports arguments -Wno-unused-function: NO Compiler for C supports arguments -Wno-conversion: NO Compiler for C supports arguments -Wno-misleading-indentation: NO Compiler for C supports arguments -Wno-incompatible-pointer-types: NO Library m found: NO ..\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\bagda\AppData\Local\Temp\pip-install-cyk95ir8\scipy_3e9529a1d9cd407a96011bdcdb5c5cd6\.mesonpy-90rqinq2\meson-logs\meson-log.txt [end of output]
解决方案
- 添加编译器到系统环境变量:安装gfortran(推荐MinGW-w64版本)后,找到安装目录下的
bin文件夹(如C:\mingw64\bin),将其路径加入系统PATH变量。重启命令行,执行gfortran --version验证是否能正常输出版本信息。 - 安装预编译二进制包:Windows系统优先用预编译包避免源码编译,执行
pip install scipy==1.9.3 --only-binary :all:(对应requirements中的版本),或直接替换requirements文件中的scipy安装方式为该命令。 - 配置Visual Studio环境:若使用Intel Fortran Compiler(ifort),安装时勾选“集成到Visual Studio”,然后打开Visual Studio开发者命令提示符执行pip安装命令,确保编译器环境被正确加载。
- 手动指定编译器路径:必须源码编译时,创建
meson_options.txt文件并添加以下内容,重新执行安装命令:[binaries] fortran = 'C:/path/to/your/gfortran.exe'
内容的提问来源于stack exchange,提问作者Tester
相关产品推荐
相关产品推荐

