如果我只是这样做:
import lightgbm as lgb
我正在
python script.py
Traceback (most recent call last):
File "script.py", line 4, in <module>
import lightgbm as lgb
File "/usr/local/lib/python2.7/site-packages/lightgbm/__init__.py", line 8, in <module>
from .basic import Booster, Dataset
File "/usr/local/lib/python2.7/site-packages/lightgbm/basic.py", line 31, in <module>
_LIB = _load_lib()
File "/usr/local/lib/python2.7/site-packages/lightgbm/basic.py", line 26, in _load_lib
lib = ctypes.cdll.LoadLibrary(lib_path[0])
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 440, in LoadLibrary
return self._dlltype(name)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 362, in __init__
self._handle = _dlopen(self._name, mode)
OSError: dlopen(/usr/local/lib/python2.7/site-packages/lightgbm/lib_lightgbm.so, 6): Library not loaded: /usr/local/opt/gcc/lib/gcc/7/libgomp.1.dylib
Referenced from: /usr/local/lib/python2.7/site-packages/lightgbm/lib_lightgbm.so
Reason: image not found
我似乎已正确安装所有内容:
python -m pip install lightgbm
Requirement already satisfied: lightgbm in /usr/local/lib/python2.7/site-packages
Requirement already satisfied: wheel in /usr/local/lib/python2.7/site-packages (from lightgbm)
Requirement already satisfied: scikit-learn in /usr/local/lib/python2.7/site-packages (from lightgbm)
Requirement already satisfied: scipy in /usr/local/lib/python2.7/site-packages (from lightgbm)
Requirement already satisfied: numpy in /usr/local/lib/python2.7/site-packages (from lightgbm)
我的GCC文件夹中有一个6个文件夹。我是否需要安装另一个版本的GCC才能使用?
答案 0 :(得分:12)
我在这里找到了类似的问题LightGBM
答案和评论可能对您有所帮助。
在Mac中构建LightGBM:
brew install cmake
brew install gcc --without-multilib
git clone --recursive https://github.com/Microsoft/LightGBM ; cd LightGBM
mkdir build ; cd build
cmake ..
make -j
然后安装:
cd ../python-packages
sudo python setup.py install --precompile
如@ecodan所述,您可能需要强制Mac使用GCC和G ++而不是默认编译器。因此,不要使用cmake ..
进行构建,请尝试:
cmake -DCMAKE_C_COMPILER=/usr/local/Cellar/gcc/6.1.0/bin/gcc-6 -DCMAKE_CXX_COMPILER=/usr/local/Cellar/gcc/6.1.0/bin/g++-6 ..
调整版本以匹配您的版本。
答案 1 :(得分:4)
以上所有答案均不适用于我。
在Mac上,如果我使用brew安装了libomp,则可以解决此问题:请参阅:link
protected void Application_AcquireRequestState(object sender, EventArgs e)
{
string culture = "en-US";
if (Request.UserLanguages != null && Request.UserLanguages.Length > 0)
{
culture = Request.UserLanguages[0];
}
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(culture);
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(culture);
}
答案 2 :(得分:3)
在MAC上你需要安装open-mpi:
brew install open-mpi
答案 3 :(得分:2)
相同的错误,不同的来源:好像我安装了 gcc 8 版本,它需要gcc 7.
通过将其切换回上一个gcc 7版本来实现:
brew switch gcc 7.3.0_1
答案 4 :(得分:1)
对于使用macports的用户,请使用以下命令替换brew解决方案的开头:
port install gcc7 cmake
export CXX=g++-mp-7 CC=gcc-mp-7
答案 5 :(得分:1)
在安装了MacPorts的MacOS High Sierra上,我执行了以下操作:
clang-5.0
/build
目录中,运行
cmake -DCMAKE_CXX_COMPILER=clang++-mp-5.0 -DCMAKE_C_COMPILER=clang-mp-5.0 ..
/python_package
目录并修改setup.py
脚本。
您需要在检查其他操作系统(包括Mac)的情况的最后修改函数compile_cpp()
。在silent_call(...)
之前,添加以下两行:
cmake_cmd.append("-DCMAKE_CXX_COMPILER=clang++-mp-5.0")
cmake_cmd.append("-DCMAKE_C_COMPILER=clang-mp-5.0")
sudo python setup.py install
。享受答案 6 :(得分:0)
我使用了从PyCharm生成的命令,它对我有用。
conda install -p {<=替换为USER_HOME_DIR>} / anaconda3 lightgbm -y
注意:我尝试安装Brew和pip,但它们对我不起作用,因为Azure ML Studio已经下载了其他版本的LightGBM,这些版本在升级到正确的软件包时引起冲突。