Mac安装Lightgbm-Anaconda

官方 Installation Guide


For Mac OS X users, gcc with OpenMP support must be installed first. Refer to  Installation Guide for installing gcc with OpenMP support.

操作步骤


0、卸载

pip uninstall lightgbm

如果使用了pip install lightgbm,会报错。所以,首先卸载。

Error: dlopen(/Users//anaconda3/envs//lib/python2.7/site-packages/lightgbm/lib_lightgbm.so, 6): Library not loaded: /usr/local/opt/gcc/lib/gcc/7/libgomp.1.dylibReferenced from: /Users//anaconda3/envs/mouse/lib/python2.7/site-packages/lightgbm/lib_lightgbm.soReason: image not found

1、Install CMake (3.2 or higher):

brew install cmake

2、Install gcc

brew install gcc

3、Run the following commands:

git clone --recursive https://github.com/Microsoft/LightGBM ; cd LightGBM
export CXX=g++-7 CC=gcc-7 # replace "7" with version of gcc installed on your machine
mkdir build ; cd build
cmake ..
make -j4

可参考: https://blog.csdn.net/Ahub_Ha/article/details/80343300

4、下面就是在你自己的anaconda环境中安装我们刚才编译好的lightgbm了:

首先要进入你的虚拟环境;

在虚拟环境中cd到你下载的LightGBM中的以下路径:

LightGBM/python-package

运行

sudo python setup.py install --precompile

输入密码...

就完成了。

运行时会出现警告


>>> import lightgbm

/Users/sumeng/app/LightGBM/LightGBM/python-package/lightgbm/__init__.py:46: UserWarning: Starting from version 2.2.1, the library file in distribution wheels for macOS is built by the Apple Clang (Xcode_8.3.3) compiler.This means that in case of installing LightGBM from PyPI via the ``pip install lightgbm`` command, you don't need to install the gcc compiler anymore.Instead of that, you need to install the OpenMP library, which is required for running LightGBM on the system with the Apple Clang compiler.You can install the OpenMP library by the following command: ``brew install libomp``.  "You can install the OpenMP library by the following command: ``brew install libomp``.", UserWarning)

不影响正常使用。如果使用下图的安装lightgbm的方式,我觉得就不会报警告

详细步骤见文章开头的Installation Guide
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容