Unable to install scikit-learn


Started learning python today. Showing an error while installing scikit-learn. Please help.

Try clicking on the “Details” link. That might help.

Collecting scikit-learn
Using cached scikit-learn-1.2.2.tar.gz (7.3 MB)
Installing build dependencies: started
Installing build dependencies: finished with status ‘error’

error: subprocess-exited-with-error

× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> [77 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
Using cached setuptools-67.7.2-py3-none-any.whl (1.1 MB)
Collecting wheel
Using cached wheel-0.40.0-py3-none-any.whl (64 kB)
Collecting Cython>=0.29.24
Using cached Cython-0.29.34-py2.py3-none-any.whl (988 kB)
Collecting oldest-supported-numpy
Using cached oldest_supported_numpy-2022.11.19-py3-none-any.whl (4.9 kB)
Collecting scipy>=1.3.2
Using cached scipy-1.10.1.tar.gz (42.4 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
    ╰─> [40 lines of output]
        The Meson build system
        Version: 1.1.0
        Source dir: /private/var/folders/lb/_pspgf5j67n_xgt_yqp0r1fr0000gn/T/pip-install-40jxu9y6/scipy_b7c0ea4dc3b84d349884f2075d921e06
        Build dir: /private/var/folders/lb/_pspgf5j67n_xgt_yqp0r1fr0000gn/T/pip-install-40jxu9y6/scipy_b7c0ea4dc3b84d349884f2075d921e06/.mesonpy-heybj2ld/build
        Build type: native build
        Project name: SciPy
        Project version: 1.10.1
        C compiler for the host machine: cc (clang 12.0.5 "Apple clang version 12.0.5 (clang-1205.0.22.11)")
        C linker for the host machine: cc ld64 650.9
        C++ compiler for the host machine: c++ (clang 12.0.5 "Apple clang version 12.0.5 (clang-1205.0.22.11)")
        C++ linker for the host machine: c++ ld64 650.9
        Cython compiler for the host machine: cython (cython 0.29.34)
        Host machine cpu family: aarch64
        Host machine cpu: aarch64
        Compiler for C supports arguments -Wno-unused-but-set-variable: NO
        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:63:0: ERROR: Unknown compiler(s): [['gfortran'], ['flang'], ['nvfortran'], ['pgfortran'], ['ifort'], ['ifx'], ['g95']]
        The following exception(s) were encountered:
        Running `gfortran --version` gave "[Errno 2] No such file or directory: 'gfortran'"
        Running `gfortran -V` gave "[Errno 2] No such file or directory: 'gfortran'"
        Running `flang --version` gave "[Errno 2] No such file or directory: 'flang'"
        Running `flang -V` gave "[Errno 2] No such file or directory: 'flang'"
        Running `nvfortran --version` gave "[Errno 2] No such file or directory: 'nvfortran'"
        Running `nvfortran -V` gave "[Errno 2] No such file or directory: 'nvfortran'"
        Running `pgfortran --version` gave "[Errno 2] No such file or directory: 'pgfortran'"
        Running `pgfortran -V` gave "[Errno 2] No such file or directory: 'pgfortran'"
        Running `ifort --version` gave "[Errno 2] No such file or directory: 'ifort'"
        Running `ifort -V` gave "[Errno 2] No such file or directory: 'ifort'"
        Running `ifx --version` gave "[Errno 2] No such file or directory: 'ifx'"
        Running `ifx -V` gave "[Errno 2] No such file or directory: 'ifx'"
        Running `g95 --version` gave "[Errno 2] No such file or directory: 'g95'"
        Running `g95 -V` gave "[Errno 2] No such file or directory: 'g95'"
  
        A full log can be found at /private/var/folders/lb/_pspgf5j67n_xgt_yqp0r1fr0000gn/T/pip-install-40jxu9y6/scipy_b7c0ea4dc3b84d349884f2075d921e06/.mesonpy-heybj2ld/build/meson-logs/meson-log.txt
        + meson setup --prefix=/Library/Frameworks/Python.framework/Versions/3.11 /private/var/folders/lb/_pspgf5j67n_xgt_yqp0r1fr0000gn/T/pip-install-40jxu9y6/scipy_b7c0ea4dc3b84d349884f2075d921e06 /private/var/folders/lb/_pspgf5j67n_xgt_yqp0r1fr0000gn/T/pip-install-40jxu9y6/scipy_b7c0ea4dc3b84d349884f2075d921e06/.mesonpy-heybj2ld/build --native-file=/private/var/folders/lb/_pspgf5j67n_xgt_yqp0r1fr0000gn/T/pip-install-40jxu9y6/scipy_b7c0ea4dc3b84d349884f2075d921e06/.mesonpy-native-file.ini -Ddebug=false -Doptimization=2
        [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.
  
  [notice] A new release of pip available: 22.3.1 -> 23.1.2
  [notice] To update, run: pip install --upgrade 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.

[notice] A new release of pip available: 22.3.1 → 23.1.2
[notice] To update, run: pip install --upgrade pip


Details shows the above. Tried the upgrading pip bit. Doesn’t seem to work.

Pypi does not have a pre-built binary of scikit-learn for your architecture, so pip tries to compile it. Compiling scikit-learn requires a fortran compiler to be installed on your system, but scikit-learn’s build system was unable to find one.

Collecting scikit-learn
Using cached scikit-learn-1.2.2.tar.gz (7.3 MB)
Installing build dependencies: started
Installing build dependencies: finished with status ‘error’

error: subprocess-exited-with-error

× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> [75 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
Using cached setuptools-67.7.2-py3-none-any.whl (1.1 MB)
Collecting wheel
Using cached wheel-0.40.0-py3-none-any.whl (64 kB)
Collecting Cython>=0.29.24
Using cached Cython-0.29.34-py2.py3-none-any.whl (988 kB)
Collecting oldest-supported-numpy
Using cached oldest_supported_numpy-2022.11.19-py3-none-any.whl (4.9 kB)
Collecting scipy>=1.3.2
Using cached scipy-1.10.1.tar.gz (42.4 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’
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
    ╰─> [41 lines of output]
        The Meson build system
        Version: 1.1.0
        Source dir: /private/var/folders/lb/_pspgf5j67n_xgt_yqp0r1fr0000gn/T/pip-install-htivmlo3/scipy_e880eabdaec048fdbc24e2d349018c33
        Build dir: /private/var/folders/lb/_pspgf5j67n_xgt_yqp0r1fr0000gn/T/pip-install-htivmlo3/scipy_e880eabdaec048fdbc24e2d349018c33/.mesonpy-xw6csnjl/build
        Build type: native build
        Project name: SciPy
        Project version: 1.10.1
        C compiler for the host machine: cc (clang 12.0.5 "Apple clang version 12.0.5 (clang-1205.0.22.11)")
        C linker for the host machine: cc ld64 650.9
        C++ compiler for the host machine: c++ (clang 12.0.5 "Apple clang version 12.0.5 (clang-1205.0.22.11)")
        C++ linker for the host machine: c++ ld64 650.9
        Cython compiler for the host machine: cython (cython 0.29.34)
        Host machine cpu family: aarch64
        Host machine cpu: aarch64
        Compiler for C supports arguments -Wno-unused-but-set-variable: NO
        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
        Fortran compiler for the host machine: gfortran (gcc 13.1.0 "GNU Fortran (Homebrew GCC 13.1.0) 13.1.0")
        Fortran linker for the host machine: gfortran ld64 530
        Compiler for Fortran supports arguments -Wno-conversion: YES
        Checking if "-Wl,--version-script" : links: NO
        Program cython found: YES (/private/var/folders/lb/_pspgf5j67n_xgt_yqp0r1fr0000gn/T/pip-build-env-worloq3s/overlay/bin/cython)
        Program python found: YES (/usr/local/bin/python3.9)
        Did not find pkg-config by name 'pkg-config'
        Found Pkg-config: NO
        Program pythran found: YES (/private/var/folders/lb/_pspgf5j67n_xgt_yqp0r1fr0000gn/T/pip-build-env-worloq3s/overlay/bin/pythran)
        Run-time dependency threads found: YES
        Library npymath found: YES
        Library npyrandom found: YES
        Did not find CMake 'cmake'
        Found CMake: NO
        Run-time dependency openblas found: NO (tried pkgconfig, framework and cmake)
        Run-time dependency openblas found: NO (tried framework)
  
        ../../scipy/meson.build:134:7: ERROR: Dependency lookup for OpenBLAS with method 'pkgconfig' failed: Pkg-config binary for machine 1 not found. Giving up.
  
        A full log can be found at /private/var/folders/lb/_pspgf5j67n_xgt_yqp0r1fr0000gn/T/pip-install-htivmlo3/scipy_e880eabdaec048fdbc24e2d349018c33/.mesonpy-xw6csnjl/build/meson-logs/meson-log.txt
        + meson setup --prefix=/Library/Frameworks/Python.framework/Versions/3.9 /private/var/folders/lb/_pspgf5j67n_xgt_yqp0r1fr0000gn/T/pip-install-htivmlo3/scipy_e880eabdaec048fdbc24e2d349018c33 /private/var/folders/lb/_pspgf5j67n_xgt_yqp0r1fr0000gn/T/pip-install-htivmlo3/scipy_e880eabdaec048fdbc24e2d349018c33/.mesonpy-xw6csnjl/build --native-file=/private/var/folders/lb/_pspgf5j67n_xgt_yqp0r1fr0000gn/T/pip-install-htivmlo3/scipy_e880eabdaec048fdbc24e2d349018c33/.mesonpy-native-file.ini -Ddebug=false -Doptimization=2
        [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.
  WARNING: You are using pip version 22.0.4; however, version 23.1.2 is available.
  You should consider upgrading via the '/usr/local/bin/python3.9 -m pip install --upgrade pip' command.
  [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.
WARNING: You are using pip version 22.0.4; however, version 23.1.2 is available.
You should consider upgrading via the ‘/usr/local/bin/python3.9 -m pip install --upgrade pip’ command.

I tried installing fortran. now its showing this error. I think i am required to install the library openblas?
But somehow unable to do so on mac

Per scikit-learn’s documentation:

At the time of writing (January 2021), the only way to get a working installation of scikit-learn on this hardware [ macos/aarch64] is to install scikit-learn and its dependencies from the conda-forge distribution, for instance using the miniforge installers:
GitHub - conda-forge/miniforge: A conda-forge distribution.

Installing scikit-learn on Apple M1 from pip is apparently not possible for now.

Okay, thanks a lot. I want to try machine learning algorithms (like decision trees, svm, random forest etc) on datasets. But since i am not able to install the relevant packages on python, should I shift to R. Or will I wont be able to install these packages on R also? Is buying a windows OS laptop the only option?

You can install them, just not via pip. See above.

You won’t be able to run scikit-learn in R, because scikit-learn is a Python package. R may have similar libraries for machine learning; I don’t know as I’m not familiar with R.

The problem is the combination of MacOS and aarch64 CPU. Windows on x86_64 architecture would certainly work, as would MacOS on x86_64, or Linux on either aarch64, x86_64, and many others.

1 Like

You could install a virtual machine inside your macOS computer with a Linux system like Fedora or Ubuntu, then use Python and scikit-learn from there.

1 Like