1.正常情况下,我们安装一个python的某个package,只要执行下列任意一行命令即可
pip install [包名称]
brew install [包名称]
conda install [包名称]
(1)因需要lightgbm包,所以我成功运行
!pip install lightgbm (备注:Jupyter环境下pip可能会失败,需要加!)
(2)然鹅,当我导入下载好的包时,报错来了。。。
import lightgbm as lgb
OSError: dlopen(/Users/didi/opt/anaconda3/lib/python3.9/site-packages/lightgbm/lib_lightgbm.so, 0x0006): Library not loaded: /usr/local/opt/libomp/lib/libomp.dylib
Referenced from: /Users/didi/opt/anaconda3/lib/python3.9/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)
通过各种baidu,找到了问题所在:
【首先】,一般是在python import一些包是遇到这个问题,本质上是需要一些外部动态链接库才能编译运行,而系统没有或有问题等,而导致出现OSError : dlopen() : Library not loaded错误。
【然后】,这个时候先具体观察Library not loaded: /usr/local/opt/libomp/lib/libomp.dylib,通常出现问题的链接库名称就在/usr/local/opt之后。
【结论】也就是说我这个报错是问题出在libomp这个库
链接:https://www.jianshu.com/p/43492dcfef33
(3)开始解决libomp这个问题吧
【首先】,执行brew install libomp,
再次报错,
那就接着baidu:https://www.jianshu.com/p/4a7a5b5d428b
// 执行下面这句命令,更换为中科院的镜像:
git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
// 把homebrew-core的镜像地址也设为中科院的国内镜像
cd "(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
// 更新,观察更新进度100%就说明成功
brew update
【然后】,终于可以安装libomp包了
【最后】再重新执行import lightgbm as lgb
大功告成!