无法在 Apple Silicon 上安装 lightgbm==3.3.3

kit*_*une 12 python numpy pip apple-silicon

这里是 的完整日志pip3 install lightgbm==3.3.3

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

有解决方法吗?

\n

Jam*_*amb 27

当您运行pip install lightgbm并在日志中看到此消息时:

为收集的包构建轮子:lightgbm

这意味着没有与您的平台(操作系统+架构+Python版本)匹配的预编译二进制文件(即wheel),并且LightGBM需要从源代码构建。

lightgbm是一个Python包包装lib_lightgbm,一个带有C API的C++库。因此,“从源代码构建”lightgbm意味着编译 C/C++ 代码,这对于 LightGBM 来说需要:

  • C 和 C++ 编译器
  • CMake构建系统
  • OpenMP 的安装

这些组件是错误消息中提到的“CMake 和所有必需的依赖项”。

clang在 macOS 上,默认情况下您应该已经安装了 C/C++ 编译器 ( )。要获取CMakeOpenMP,请运行以下命令。

brew install cmake libomp
Run Code Online (Sandbox Code Playgroud)

注意:lightgbmv3.3.3 及更早版本不支持截至本文撰写时可用的最新 OpenMP 版本 (v15.x)。这已在microsoft/LightGBM#5563中修复。如果您最终使用了 OpenMP>=15.0并且lightgbm>=4.0尚未从 PyPI 获得,请降级 OpenMP 或构建开发版本lightgbm(请参阅文档中的“从 GitHub 安装” )。