1、安装命令
pip3 install lightgbm -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
python命令行模式下,import lightgbm报错,错误信息如下所示
import lightgbm
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/lightgbm/__init__.py", line 8, in <module>
from .basic import Booster, Dataset, Sequence, register_logger
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/lightgbm/basic.py", line 110, in <module>
_LIB = _load_lib()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/lightgbm/basic.py", line 101, in _load_lib
lib = ctypes.cdll.LoadLibrary(lib_path[0])
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ctypes/__init__.py", line 442, in LoadLibrary
return self._dlltype(name)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ctypes/__init__.py", line 364, in __init__
self._handle = _dlopen(self._name, mode)
OSError: dlopen(/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/lightgbm/lib_lightgbm.so, 0x0006): Library not loaded: '/usr/local/opt/libomp/lib/libomp.dylib'
Referenced from: '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/lightgbm/lib_lightgbm.so'
Reason: tried: '/usr/local/opt/libomp/lib/libomp.dylib' (no such file), '/usr/local/lib/libomp.dylib' (no such file), '/usr/lib/libomp.dylib' (no such file)
2、解决:安装libomp
brew install libomp
出现错误,按提示执行命令
Error: You have not agreed to the Xcode license. Please resolve this by running:
sudo xcodebuild -license accept
重新brew install libomp,如果还有出错,解决方式如下:
参考文章链接:brew install libomp失败解决方法
检验一下结果
终端输入python3
Python 3.7.4rc1 (v3.7.4rc1:b26441ee1f, Jun 18 2019, 17:48:48)
[Clang 6.0 (clang-600.0.57)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import lightgbm
>>>
OK,解决~