Arturo Sbr
Arturo Sbr

Reputation: 6343

Unable to pip install old version of scikit-learn

I need to use scikit-learn==0.23.1 (or older) to make my project compatible with an AWS Lambda layer.

As suggested by this post, I tried pip3 install scikit-learn==0.23.1, but it did not work.

I then found an issue that suggested pip3 install -U scikit-learn==0.23.1 --no-cache-dir, but it did not work either.

I am using Python 3.11.1 on an M1 MacBook Air. These are the error logs from running pip3 install scikit-learn==0.23.1:

Collecting scikit-learn==0.23.1
  Using cached scikit-learn-0.23.1.tar.gz (7.2 MB)
  Installing build dependencies ... error
  error: subprocess-exited-with-error
  
  × pip subprocess to install build dependencies did not run successfully.
  │ exit code: 1
  ╰─> [107 lines of output]
      Ignoring numpy: markers 'python_version == "3.6" and platform_system != "AIX" and platform_python_implementation == "CPython"' don't match your environment
      Ignoring numpy: markers 'python_version == "3.6" and platform_system != "AIX" and platform_python_implementation != "CPython"' don't match your environment
      Ignoring numpy: markers 'python_version == "3.7" and platform_system != "AIX"' don't match your environment
      Ignoring numpy: markers 'python_version == "3.6" and platform_system == "AIX"' don't match your environment
      Ignoring numpy: markers 'python_version == "3.7" and platform_system == "AIX"' don't match your environment
      Ignoring numpy: markers 'python_version >= "3.8" and platform_system == "AIX"' don't match your environment
      Collecting setuptools
        Using cached setuptools-67.2.0-py3-none-any.whl (1.1 MB)
      Collecting wheel
        Using cached wheel-0.38.4-py3-none-any.whl (36 kB)
      Collecting Cython>=0.28.5
        Using cached Cython-0.29.33-py2.py3-none-any.whl (987 kB)
      Collecting numpy==1.17.3
        Using cached numpy-1.17.3.zip (6.4 MB)
        Preparing metadata (setup.py): started
        Preparing metadata (setup.py): finished with status 'done'
      Collecting scipy>=0.19.1
        Using cached scipy-1.10.0-cp311-cp311-macosx_12_0_arm64.whl (28.7 MB)
        Using cached scipy-1.9.3-cp311-cp311-macosx_12_0_arm64.whl (28.4 MB)
        Using cached scipy-1.9.2-cp311-cp311-macosx_12_0_arm64.whl (28.4 MB)
        Using cached scipy-1.9.1.tar.gz (42.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 'error'
        error: subprocess-exited-with-error
      
        × Getting requirements to build wheel did not run successfully.
        │ exit code: 1
        ╰─> [67 lines of output]
            The Meson build system
            Version: 0.62.2
            Source dir: /private/var/folders/c2/v1x2pn511b79mxpbdj208p780000gn/T/pip-install-txosa8qz/scipy_734bcce5e1d549fab1cee5a52c8d7f28
            Build dir: /private/var/folders/c2/v1x2pn511b79mxpbdj208p780000gn/T/pip-install-txosa8qz/scipy_734bcce5e1d549fab1cee5a52c8d7f28/.mesonpy-7pg6lokl/build
            Build type: native build
            Project name: SciPy
            Project version: 1.9.1
            C compiler for the host machine: cc (clang 14.0.0 "Apple clang version 14.0.0 (clang-1400.0.29.202)")
            C linker for the host machine: cc ld64 820.1
            C++ compiler for the host machine: c++ (clang 14.0.0 "Apple clang version 14.0.0 (clang-1400.0.29.202)")
            C++ linker for the host machine: c++ ld64 820.1
            Host machine cpu family: aarch64
            Host machine cpu: arm64
            Compiler for C supports arguments -Wno-unused-but-set-variable: YES
            Library m found: YES
      
            ../../meson.build:41:0: ERROR: Unknown compiler(s): [['gfortran'], ['flang'], ['nvfortran'], ['pgfortran'], ['ifort'], ['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 "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/c2/v1x2pn511b79mxpbdj208p780000gn/T/pip-install-txosa8qz/scipy_734bcce5e1d549fab1cee5a52c8d7f28/.mesonpy-7pg6lokl/build/meson-logs/meson-log.txt
            + meson setup --native-file=/private/var/folders/c2/v1x2pn511b79mxpbdj208p780000gn/T/pip-install-txosa8qz/scipy_734bcce5e1d549fab1cee5a52c8d7f28/.mesonpy-native-file.ini -Ddebug=false -Doptimization=2 --prefix=/Library/Frameworks/Python.framework/Versions/3.11 /private/var/folders/c2/v1x2pn511b79mxpbdj208p780000gn/T/pip-install-txosa8qz/scipy_734bcce5e1d549fab1cee5a52c8d7f28 /private/var/folders/c2/v1x2pn511b79mxpbdj208p780000gn/T/pip-install-txosa8qz/scipy_734bcce5e1d549fab1cee5a52c8d7f28/.mesonpy-7pg6lokl/build
            Traceback (most recent call last):
              File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
                main()
              File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
                json_out['return_val'] = hook(**hook_input['kwargs'])
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
              File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
                return hook(config_settings)
                       ^^^^^^^^^^^^^^^^^^^^^
              File "/private/var/folders/c2/v1x2pn511b79mxpbdj208p780000gn/T/pip-build-env-u2xs3lnb/overlay/lib/python3.11/site-packages/mesonpy/__init__.py", line 969, in get_requires_for_build_wheel
                with _project(config_settings) as project:
              File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/contextlib.py", line 137, in __enter__
                return next(self.gen)
                       ^^^^^^^^^^^^^^
              File "/private/var/folders/c2/v1x2pn511b79mxpbdj208p780000gn/T/pip-build-env-u2xs3lnb/overlay/lib/python3.11/site-packages/mesonpy/__init__.py", line 948, in _project
                with Project.with_temp_working_dir(
              File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/contextlib.py", line 137, in __enter__
                return next(self.gen)
                       ^^^^^^^^^^^^^^
              File "/private/var/folders/c2/v1x2pn511b79mxpbdj208p780000gn/T/pip-build-env-u2xs3lnb/overlay/lib/python3.11/site-packages/mesonpy/__init__.py", line 777, in with_temp_working_dir
                yield cls(source_dir, tmpdir, build_dir)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
              File "/private/var/folders/c2/v1x2pn511b79mxpbdj208p780000gn/T/pip-build-env-u2xs3lnb/overlay/lib/python3.11/site-packages/mesonpy/__init__.py", line 682, in __init__
                self._configure(reconfigure=bool(build_dir) and not native_file_mismatch)
              File "/private/var/folders/c2/v1x2pn511b79mxpbdj208p780000gn/T/pip-build-env-u2xs3lnb/overlay/lib/python3.11/site-packages/mesonpy/__init__.py", line 713, in _configure
                self._meson(
              File "/private/var/folders/c2/v1x2pn511b79mxpbdj208p780000gn/T/pip-build-env-u2xs3lnb/overlay/lib/python3.11/site-packages/mesonpy/__init__.py", line 696, in _meson
                return self._proc('meson', *args)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^
              File "/private/var/folders/c2/v1x2pn511b79mxpbdj208p780000gn/T/pip-build-env-u2xs3lnb/overlay/lib/python3.11/site-packages/mesonpy/__init__.py", line 691, in _proc
                subprocess.check_call(list(args))
              File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/subprocess.py", line 413, in check_call
                raise CalledProcessError(retcode, cmd)
            subprocess.CalledProcessError: Command '['meson', 'setup', '--native-file=/private/var/folders/c2/v1x2pn511b79mxpbdj208p780000gn/T/pip-install-txosa8qz/scipy_734bcce5e1d549fab1cee5a52c8d7f28/.mesonpy-native-file.ini', '-Ddebug=false', '-Doptimization=2', '--prefix=/Library/Frameworks/Python.framework/Versions/3.11', '/private/var/folders/c2/v1x2pn511b79mxpbdj208p780000gn/T/pip-install-txosa8qz/scipy_734bcce5e1d549fab1cee5a52c8d7f28', '/private/var/folders/c2/v1x2pn511b79mxpbdj208p780000gn/T/pip-install-txosa8qz/scipy_734bcce5e1d549fab1cee5a52c8d7f28/.mesonpy-7pg6lokl/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.

Any ideas on how to successfully install version 0.23.1 of scikit-learn?

Upvotes: 1

Views: 1397

Answers (1)

Corralien
Corralien

Reputation: 120559

sklearn==0.23.1 has not distribution package for Python==3.11, only for 3.6, 3.7 and 3.8 so you have to install from source but your need some binaries like gfortran, etc.

To installing on M1, use miniforge:

The recently introduced macos/arm64 platform (sometimes also known as macos/aarch64) requires the open source community to upgrade the build configuration and automation to properly support it. At the time of writing (January 2021), the only way to get a working installation of scikit-learn on this hardware is to install scikit-learn and its dependencies from the conda-forge distribution, for instance using the miniforge installers:

https://scikit-learn.org/stable/install.html#installing-on-apple-silicon-m1-hardware

Upvotes: 2

Related Questions