无法在苹果芯片上安装lightgbm==3.3.3。

10

以下是执行 pip3 install lightgbm==3.3.3 命令的完整日志记录。

me % pip3 install lightgbm==3.3.3
Collecting lightgbm==3.3.3
  Using cached lightgbm-3.3.3.tar.gz (1.5 MB)
  Preparing metadata (setup.py) ... done
Requirement already satisfied: wheel in /opt/homebrew/lib/python3.10/site-packages (from lightgbm==3.3.3) (0.37.1)
Collecting numpy
  Using cached numpy-1.23.5-cp310-cp310-macosx_11_0_arm64.whl (13.4 MB)
Collecting scipy
  Using cached scipy-1.9.3-cp310-cp310-macosx_12_0_arm64.whl (28.5 MB)
Collecting scikit-learn!=0.22.0
  Downloading scikit_learn-1.1.3-cp310-cp310-macosx_12_0_arm64.whl (7.7 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 7.7/7.7 MB 4.7 MB/s eta 0:00:00
Collecting threadpoolctl>=2.0.0
  Downloading threadpoolctl-3.1.0-py3-none-any.whl (14 kB)
Collecting joblib>=1.0.0
  Using cached joblib-1.2.0-py3-none-any.whl (297 kB)
Building wheels for collected packages: lightgbm
  Building wheel for lightgbm (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [86 lines of output]
      running bdist_wheel
      /opt/homebrew/lib/python3.10/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
        warnings.warn(
      running build
      running build_py
      creating build
      creating build/lib
      creating build/lib/lightgbm
      copying lightgbm/callback.py -> build/lib/lightgbm
      copying lightgbm/compat.py -> build/lib/lightgbm
      copying lightgbm/plotting.py -> build/lib/lightgbm
      copying lightgbm/__init__.py -> build/lib/lightgbm
      copying lightgbm/engine.py -> build/lib/lightgbm
      copying lightgbm/dask.py -> build/lib/lightgbm
      copying lightgbm/basic.py -> build/lib/lightgbm
      copying lightgbm/libpath.py -> build/lib/lightgbm
      copying lightgbm/sklearn.py -> build/lib/lightgbm
      running egg_info
      writing lightgbm.egg-info/PKG-INFO
      writing dependency_links to lightgbm.egg-info/dependency_links.txt
      writing requirements to lightgbm.egg-info/requires.txt
      writing top-level names to lightgbm.egg-info/top_level.txt
      reading manifest file 'lightgbm.egg-info/SOURCES.txt'
      reading manifest template 'MANIFEST.in'
      no previously-included directories found matching 'build'
      warning: no files found matching '*.so' under directory 'lightgbm'
      warning: no files found matching '*.so' under directory 'compile'
      warning: no files found matching '*.dll' under directory 'compile/Release'
      warning: no files found matching '*.dll' under directory 'compile/windows/x64/DLL'
      warning: no previously-included files matching '*.py[co]' found anywhere in distribution
      warning: no previously-included files found matching 'compile/external_libs/compute/.git'
      adding license file 'LICENSE'
      writing manifest file 'lightgbm.egg-info/SOURCES.txt'
      copying lightgbm/VERSION.txt -> build/lib/lightgbm
      installing to build/bdist.macosx-13-arm64/wheel
      running install
      INFO:LightGBM:Starting to compile the library.
      INFO:LightGBM:Starting to compile with CMake.
      Traceback (most recent call last):
        File "/private/var/folders/qf/7kpp7kws2bs9ljbxdl6vf9480000gn/T/pip-install-qdmnvrdo/lightgbm_7e71affc27c54e8fb3f78d9ef73bd942/setup.py", line 95, in silent_call
          subprocess.check_call(cmd, stderr=log, stdout=log)
        File "/opt/homebrew/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py", line 364, in check_call
          retcode = call(*popenargs, **kwargs)
        File "/opt/homebrew/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py", line 345, in call
          with Popen(*popenargs, **kwargs) as p:
        File "/opt/homebrew/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py", line 971, in __init__
          self._execute_child(args, executable, preexec_fn, close_fds,
        File "/opt/homebrew/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py", line 1847, in _execute_child
          raise child_exception_type(errno_num, err_msg, err_filename)
      FileNotFoundError: [Errno 2] No such file or directory: 'cmake'
      
      During handling of the above exception, another exception occurred:
      
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/private/var/folders/qf/7kpp7kws2bs9ljbxdl6vf9480000gn/T/pip-install-qdmnvrdo/lightgbm_7e71affc27c54e8fb3f78d9ef73bd942/setup.py", line 334, in <module>
          setup(name='lightgbm',
        File "/opt/homebrew/lib/python3.10/site-packages/setuptools/__init__.py", line 87, in setup
          return distutils.core.setup(**attrs)
        File "/opt/homebrew/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 185, in setup
          return run_commands(dist)
        File "/opt/homebrew/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
          dist.run_commands()
        File "/opt/homebrew/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 968, in run_commands
          self.run_command(cmd)
        File "/opt/homebrew/lib/python3.10/site-packages/setuptools/dist.py", line 1217, in run_command
          super().run_command(command)
        File "/opt/homebrew/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 987, in run_command
          cmd_obj.run()
        File "/opt/homebrew/lib/python3.10/site-packages/wheel/bdist_wheel.py", line 335, in run
          self.run_command('install')
        File "/opt/homebrew/lib/python3.10/site-packages/setuptools/_distutils/cmd.py", line 319, in run_command
          self.distribution.run_command(command)
        File "/opt/homebrew/lib/python3.10/site-packages/setuptools/dist.py", line 1217, in run_command
          super().run_command(command)
        File "/opt/homebrew/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 987, in run_command
          cmd_obj.run()
        File "/private/var/folders/qf/7kpp7kws2bs9ljbxdl6vf9480000gn/T/pip-install-qdmnvrdo/lightgbm_7e71affc27c54e8fb3f78d9ef73bd942/setup.py", line 248, in run
          compile_cpp(use_mingw=self.mingw, use_gpu=self.gpu, use_cuda=self.cuda, use_mpi=self.mpi,
        File "/private/var/folders/qf/7kpp7kws2bs9ljbxdl6vf9480000gn/T/pip-install-qdmnvrdo/lightgbm_7e71affc27c54e8fb3f78d9ef73bd942/setup.py", line 198, in compile_cpp
          silent_call(cmake_cmd, raise_error=True, error_msg='Please install CMake and all required dependencies first')
        File "/private/var/folders/qf/7kpp7kws2bs9ljbxdl6vf9480000gn/T/pip-install-qdmnvrdo/lightgbm_7e71affc27c54e8fb3f78d9ef73bd942/setup.py", line 99, in silent_call
          raise Exception("\n".join((error_msg, LOG_NOTICE)))
      Exception: Please install CMake and all required dependencies first
      The full version of error log was saved into /Users/me/LightGBM_compilation.log
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for lightgbm
  Running setup.py clean for lightgbm
Failed to build lightgbm
Installing collected packages: threadpoolctl, numpy, joblib, scipy, scikit-learn, lightgbm
  Running setup.py install for lightgbm ... error
  error: subprocess-exited-with-error
  
  × Running setup.py install for lightgbm did not run successfully.
  │ exit code: 1
  ╰─> [45 lines of output]
      running install
      /opt/homebrew/lib/python3.10/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
        warnings.warn(
      INFO:LightGBM:Starting to compile the library.
      INFO:LightGBM:Starting to compile with CMake.
      Traceback (most recent call last):
        File "/private/var/folders/qf/7kpp7kws2bs9ljbxdl6vf9480000gn/T/pip-install-qdmnvrdo/lightgbm_7e71affc27c54e8fb3f78d9ef73bd942/setup.py", line 95, in silent_call
          subprocess.check_call(cmd, stderr=log, stdout=log)
        File "/opt/homebrew/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py", line 364, in check_call
          retcode = call(*popenargs, **kwargs)
        File "/opt/homebrew/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py", line 345, in call
          with Popen(*popenargs, **kwargs) as p:
        File "/opt/homebrew/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py", line 971, in __init__
          self._execute_child(args, executable, preexec_fn, close_fds,
        File "/opt/homebrew/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py", line 1847, in _execute_child
          raise child_exception_type(errno_num, err_msg, err_filename)
      FileNotFoundError: [Errno 2] No such file or directory: 'cmake'
      
      During handling of the above exception, another exception occurred:
      
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/private/var/folders/qf/7kpp7kws2bs9ljbxdl6vf9480000gn/T/pip-install-qdmnvrdo/lightgbm_7e71affc27c54e8fb3f78d9ef73bd942/setup.py", line 334, in <module>
          setup(name='lightgbm',
        File "/opt/homebrew/lib/python3.10/site-packages/setuptools/__init__.py", line 87, in setup
          return distutils.core.setup(**attrs)
        File "/opt/homebrew/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 185, in setup
          return run_commands(dist)
        File "/opt/homebrew/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
          dist.run_commands()
        File "/opt/homebrew/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 968, in run_commands
          self.run_command(cmd)
        File "/opt/homebrew/lib/python3.10/site-packages/setuptools/dist.py", line 1217, in run_command
          super().run_command(command)
        File "/opt/homebrew/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 987, in run_command
          cmd_obj.run()
        File "/private/var/folders/qf/7kpp7kws2bs9ljbxdl6vf9480000gn/T/pip-install-qdmnvrdo/lightgbm_7e71affc27c54e8fb3f78d9ef73bd942/setup.py", line 248, in run
          compile_cpp(use_mingw=self.mingw, use_gpu=self.gpu, use_cuda=self.cuda, use_mpi=self.mpi,
        File "/private/var/folders/qf/7kpp7kws2bs9ljbxdl6vf9480000gn/T/pip-install-qdmnvrdo/lightgbm_7e71affc27c54e8fb3f78d9ef73bd942/setup.py", line 198, in compile_cpp
          silent_call(cmake_cmd, raise_error=True, error_msg='Please install CMake and all required dependencies first')
        File "/private/var/folders/qf/7kpp7kws2bs9ljbxdl6vf9480000gn/T/pip-install-qdmnvrdo/lightgbm_7e71affc27c54e8fb3f78d9ef73bd942/setup.py", line 99, in silent_call
          raise Exception("\n".join((error_msg, LOG_NOTICE)))
      Exception: Please install CMake and all required dependencies first
      The full version of error log was saved into /Users/me/LightGBM_compilation.log
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> lightgbm

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

这个有解决方法吗?

2
一个可能的解决方法在错误信息中:异常:请先安装CMake和所有必需的依赖项 - ForceBru
重新安装cmake对我有用,现在使用brew install cmake - shogitai
1个回答

22
当你运行pip install lightgbm并在日志中看到以下信息时:

Building wheels for collected packages: lightgbm

这意味着没有匹配你的平台(操作系统+架构+Python版本)的预编译二进制文件(即wheel),需要从源代码构建LightGBM。 lightgbm是一个Python包装lib_lightgbm的C++库,具有C API。所以对于lightgbm来说,“从源代码构建”意味着编译这个C/C++代码,对于LightGBM来说需要:
  • C和C++编译器
  • CMake构建系统
  • 已安装的OpenMP
这些组件是错误消息中提到的“CMake和所有必需的依赖项”。
在macOS上,你应该已经默认安装了一个C/C++编译器(clang)。要获取CMake和OpenMP,请运行以下命令。
brew install cmake libomp

注意:截至撰写本文,lightgbm v3.3.3 及更早版本不支持最新的 OpenMP 版本(v15.x)。这个问题在 microsoft/LightGBM#5563 中已经修复。如果你的 OpenMP 版本是 >=15.0,而且 PyPI 上尚未提供 lightgbm>=4.0 的版本,则需要降级 OpenMP 或构建开发版的 lightgbm(请参阅文档中的“从 GitHub 安装”)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接