LightGBM: Error when trying to use source-built python package for M1 mac

Description

I’m trying to do some development on my M1 Mac, and while I’m able to generate the libraries and executables as expected, when try to run the Python tests I get the following error:

E OSError: dlopen(/Users/XXX/opt/anaconda3/envs/lgbm-dev/lib/python3.9/site-packages/lightgbm/lib_lightgbm.so, 6): no suitable image found. Did find: E /Users/XXX/opt/anaconda3/envs/lgbm-dev/lib/python3.9/site-packages/lightgbm/lib_lightgbm.so: mach-o, but wrong architecture E /Users/XXX/opt/anaconda3/envs/lgbm-dev/lib/python3.9/site-packages/lightgbm/lib_lightgbm.so: mach-o, but wrong architecture

Reproducible example

# On fresh pull of master on an M1 Mac:
conda create --name lgbm-dev numpy scipy scikit-learn pytest cmake
conda activate lgbm-dev
# <Clone LightGBM master and cd into it>
cd python-package
python setup.py install
cd ..
pytest tests/

Environment info

LightGBM version or commit hash:

commit 8f4126d66065347519185b2f687d423117d67b1b

Command(s) you used to install LightGBM

python setup.py install

uname -a
Darwin xxx.xxx.xx 20.6.0 Darwin Kernel Version 20.6.0: Tue Oct 12 18:33:38 PDT 2021; root:xnu-7195.141.8~1/RELEASE_ARM64_T8101 arm64

conda list:

# Name                    Version                   Build  Channel
attrs                     21.2.0             pyhd3eb1b0_0
blas                      1.0                         mkl
bzip2                     1.0.8                h1de35cc_0
c-ares                    1.17.1               h9ed2024_0
ca-certificates           2021.10.26           hecd8cb5_2
certifi                   2021.10.8        py39hecd8cb5_0
cmake                     3.19.6               h04fa861_0
expat                     2.4.1                h23ab428_2
iniconfig                 1.1.1              pyhd3eb1b0_0
intel-openmp              2021.4.0          hecd8cb5_3538
joblib                    1.1.0              pyhd3eb1b0_0
krb5                      1.19.2               hcd88c3b_0
libcurl                   7.78.0               hb8e4fae_0
libcxx                    12.0.0               h2f01273_0
libedit                   3.1.20210910         hca72f7f_0
libev                     4.33                 h9ed2024_1
libffi                    3.3                  hb1e8313_2
libgfortran               3.0.1                h93005f0_2
libnghttp2                1.46.0               ha29bfda_0
libssh2                   1.9.0                ha12b0ac_1
libuv                     1.40.0               haf1e3a3_0
lightgbm                  3.3.1.99                 pypi_0    pypi
llvm-openmp               12.0.0               h0dcd299_1
lz4-c                     1.9.3                h23ab428_1
mkl                       2021.4.0           hecd8cb5_637
mkl-service               2.4.0            py39h9ed2024_0
mkl_fft                   1.3.1            py39h4ab4a9b_0
mkl_random                1.2.2            py39hb2f4e1b_0
more-itertools            8.12.0             pyhd3eb1b0_0
ncurses                   6.3                  hca72f7f_2
numpy                     1.21.2           py39h4b4dc7a_0
numpy-base                1.21.2           py39he0bd621_0
openssl                   1.1.1l               h9ed2024_0
packaging                 21.3               pyhd3eb1b0_0
pip                       21.2.4           py39hecd8cb5_0
pluggy                    0.13.1           py39hecd8cb5_0
py                        1.10.0             pyhd3eb1b0_0
pyparsing                 3.0.4              pyhd3eb1b0_0
pytest                    6.2.4            py39hecd8cb5_2
python                    3.9.7                h88f2d9e_1
readline                  8.1                  h9ed2024_0
rhash                     1.4.1                hbcfaee0_1
scikit-learn              1.0.1            py39hae1ba45_0
scipy                     1.7.1            py39h88652d9_2
setuptools                58.0.4           py39hecd8cb5_0
six                       1.16.0             pyhd3eb1b0_0
sqlite                    3.36.0               hce871da_0
threadpoolctl             2.2.0              pyh0d69192_0
tk                        8.6.11               h7bc2e8c_0
toml                      0.10.2             pyhd3eb1b0_0
tzdata                    2021e                hda174b7_0
wheel                     0.37.0             pyhd3eb1b0_1
xz                        5.2.5                h1de35cc_0
zlib                      1.2.11               h1de35cc_3
zstd                      1.4.9                h322a384_0

Additional Comments

This seems to be a common problem with other Python packages and M1 Macs, but I haven’t been able to find a consistent solution.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 35

Most upvoted comments

I strongly believe that @thvasilo is right and this is

a common problem with other Python packages and M1 Macs

and we can’t do anything with it. Probably this affects Python 3.9 version only.

Some random examples:

@thvasilo Also, raw logs may help. Please install LightGBM in the following way:

brew install cmake
brew install libomp
git clone --recursive https://github.com/microsoft/LightGBM
cd LightGBM
mkdir build
cd build
cmake ..
make -j4

according to https://lightgbm.readthedocs.io/en/latest/Installation-Guide.html#build-from-github and after that run

cd ../python-package
python setup.py install --precompile

Recently, I’ve had a chance to work on Mac M1 for a few minutes. So I checked whether LightGBM can be installed on it. Good news, it can in both ways: via manual compilation and indirectly triggered compilation after running pip install lightgbm!

photo5264971280707337372

Here are logs of the commands that I used (according to our official installation guide) to install lightgbm package and successfully run it on arm64 architecture.

brew install cmake
brew install libomp

For brew commands logs are unavailable unfortunately.

(base) leonidalekseev@MacBook-Air-Leonid ~ % git clone --recursive https://github.com/microsoft/LightGBM.git
Cloning into 'LightGBM'...
remote: Enumerating objects: 25115, done.
remote: Counting objects: 100% (791/791), done.
remote: Compressing objects: 100% (434/434), done.
remote: Total 25115 (delta 508), reused 568 (delta 350), pack-reused 24324
Receiving objects: 100% (25115/25115), 18.73 MiB | 691.00 KiB/s, done.
Resolving deltas: 100% (18457/18457), done.
Submodule 'include/boost/compute' (https://github.com/boostorg/compute) registered for path 'external_libs/compute'
Submodule 'eigen' (https://gitlab.com/libeigen/eigen.git) registered for path 'external_libs/eigen'
Submodule 'external_libs/fast_double_parser' (https://github.com/lemire/fast_double_parser.git) registered for path 'external_libs/fast_double_parser'
Submodule 'external_libs/fmt' (https://github.com/fmtlib/fmt.git) registered for path 'external_libs/fmt'
Cloning into '/Users/leonidalekseev/LightGBM/external_libs/compute'...
remote: Enumerating objects: 21733, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 21733 (delta 1), reused 2 (delta 0), pack-reused 21728
Receiving objects: 100% (21733/21733), 8.51 MiB | 711.00 KiB/s, done.
Resolving deltas: 100% (17567/17567), done.
Cloning into '/Users/leonidalekseev/LightGBM/external_libs/eigen'...
remote: Enumerating objects: 114927, done.
remote: Counting objects: 100% (91/91), done.
remote: Compressing objects: 100% (73/73), done.
remote: Total 114927 (delta 49), reused 44 (delta 18), pack-reused 114836
Receiving objects: 100% (114927/114927), 102.09 MiB | 1.06 MiB/s, done.
Resolving deltas: 100% (94768/94768), done.
Cloning into '/Users/leonidalekseev/LightGBM/external_libs/fast_double_parser'...
remote: Enumerating objects: 692, done.
remote: Counting objects: 100% (192/192), done.
remote: Compressing objects: 100% (124/124), done.
remote: Total 692 (delta 95), reused 99 (delta 41), pack-reused 500
Receiving objects: 100% (692/692), 802.86 KiB | 769.00 KiB/s, done.
Resolving deltas: 100% (349/349), done.
Cloning into '/Users/leonidalekseev/LightGBM/external_libs/fmt'...
remote: Enumerating objects: 28976, done.
remote: Counting objects: 100% (336/336), done.
remote: Compressing objects: 100% (93/93), done.
remote: Total 28976 (delta 199), reused 306 (delta 192), pack-reused 28640
Receiving objects: 100% (28976/28976), 13.87 MiB | 689.00 KiB/s, done.
Resolving deltas: 100% (19550/19550), done.
Submodule path 'external_libs/compute': checked out '36350b7de849300bd3d72a05d8bf890ca405a014'
Submodule path 'external_libs/eigen': checked out '3147391d946bb4b6c68edd901f2add6ac1f31f8c'
Submodule path 'external_libs/fast_double_parser': checked out 'ace60646c02dc54c57f19d644e49a61e7e7758ec'
Submodule 'benchmark/dependencies/abseil-cpp' (https://github.com/abseil/abseil-cpp.git) registered for path 'external_libs/fast_double_parser/benchmarks/dependencies/abseil-cpp'
Submodule 'benchmark/dependencies/double-conversion' (https://github.com/google/double-conversion.git) registered for path 'external_libs/fast_double_parser/benchmarks/dependencies/double-conversion'
Cloning into '/Users/leonidalekseev/LightGBM/external_libs/fast_double_parser/benchmarks/dependencies/abseil-cpp'...
remote: Enumerating objects: 16312, done.
remote: Counting objects: 100% (438/438), done.
remote: Compressing objects: 100% (317/317), done.
remote: Total 16312 (delta 251), reused 207 (delta 121), pack-reused 15874
Receiving objects: 100% (16312/16312), 10.64 MiB | 910.00 KiB/s, done.
Resolving deltas: 100% (12531/12531), done.
Cloning into '/Users/leonidalekseev/LightGBM/external_libs/fast_double_parser/benchmarks/dependencies/double-conversion'...
remote: Enumerating objects: 1338, done.
remote: Counting objects: 100% (182/182), done.
remote: Compressing objects: 100% (140/140), done.
remote: Total 1338 (delta 98), reused 85 (delta 35), pack-reused 1156
Receiving objects: 100% (1338/1338), 7.14 MiB | 785.00 KiB/s, done.
Resolving deltas: 100% (870/870), done.
Submodule path 'external_libs/fast_double_parser/benchmarks/dependencies/abseil-cpp': checked out 'd936052d32a5b7ca08b0199a6724724aea432309'
Submodule path 'external_libs/fast_double_parser/benchmarks/dependencies/double-conversion': checked out 'f4cb2384efa55dee0e6652f8674b05763441ab09'
Submodule path 'external_libs/fmt': checked out 'b6f4ceaed0a0a24ccf575fab6c56dd50ccf6f1a9'

(base) leonidalekseev@MacBook-Air-Leonid ~ % cd LightGBM

(base) leonidalekseev@MacBook-Air-Leonid LightGBM % mkdir build

(base) leonidalekseev@MacBook-Air-Leonid LightGBM % cd build

(base) leonidalekseev@MacBook-Air-Leonid build % cmake ..
-- The C compiler identification is AppleClang 13.0.0.13000029
-- The CXX compiler identification is AppleClang 13.0.0.13000029
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenMP_C: -Xclang -fopenmp (found version "5.0")
-- Found OpenMP_CXX: -Xclang -fopenmp (found version "5.0")
-- Found OpenMP: TRUE (found version "5.0")
-- Performing Test MM_PREFETCH
-- Performing Test MM_PREFETCH - Failed
-- Performing Test MM_MALLOC
-- Performing Test MM_MALLOC - Success
-- Using _mm_malloc
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/leonidalekseev/LightGBM/build

(base) leonidalekseev@MacBook-Air-Leonid build % make -j4
[  5%] Building CXX object CMakeFiles/lightgbm_capi_objs.dir/src/c_api.cpp.o
[  5%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/boosting/boosting.cpp.o
[  8%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/boosting/gbdt.cpp.o
[ 10%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/boosting/gbdt_model_text.cpp.o
[ 13%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/boosting/gbdt_prediction.cpp.o
[ 16%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/boosting/prediction_early_stop.cpp.o
[ 18%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/io/bin.cpp.o
[ 21%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/io/config.cpp.o
[ 24%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/io/config_auto.cpp.o
[ 29%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/io/dataset_loader.cpp.o
[ 29%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/io/dataset.cpp.o
[ 29%] Built target lightgbm_capi_objs
[ 32%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/io/file_io.cpp.o
[ 35%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/io/json11.cpp.o
[ 37%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/io/metadata.cpp.o
[ 40%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/io/parser.cpp.o
[ 43%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/io/train_share_states.cpp.o
[ 45%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/io/tree.cpp.o
[ 48%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/metric/dcg_calculator.cpp.o
[ 51%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/metric/metric.cpp.o
[ 54%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/network/ifaddrs_patch.cpp.o
[ 56%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/network/linker_topo.cpp.o
[ 59%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/network/linkers_mpi.cpp.o
[ 62%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/network/linkers_socket.cpp.o
[ 64%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/network/network.cpp.o
[ 67%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/objective/objective_function.cpp.o
[ 70%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/treelearner/cuda_tree_learner.cpp.o
[ 72%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/treelearner/data_parallel_tree_learner.cpp.o
[ 75%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/treelearner/feature_parallel_tree_learner.cpp.o
[ 78%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/treelearner/gpu_tree_learner.cpp.o
[ 81%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/treelearner/linear_tree_learner.cpp.o
[ 83%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/treelearner/serial_tree_learner.cpp.o
[ 86%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/treelearner/tree_learner.cpp.o
[ 89%] Building CXX object CMakeFiles/lightgbm_objs.dir/src/treelearner/voting_parallel_tree_learner.cpp.o
[ 89%] Built target lightgbm_objs
[ 97%] Building CXX object CMakeFiles/lightgbm.dir/src/application/application.cpp.o
[ 97%] Linking CXX shared library ../lib_lightgbm.so
[ 97%] Building CXX object CMakeFiles/lightgbm.dir/src/main.cpp.o
[ 97%] Built target _lightgbm
[100%] Linking CXX executable ../lightgbm
[100%] Built target lightgbm

(base) leonidalekseev@MacBook-Air-Leonid build % cd ../python-package

(base) leonidalekseev@MacBook-Air-Leonid python-package % python setup.py install --precompile
running install
running build
running build_py
creating build
creating build/lib
creating build/lib/lightgbm
copying lightgbm/callback.py -> build/lib/lightgbm
copying lightgbm/compat.py -> build/lib/lightgbm
copying lightgbm/plotting.py -> build/lib/lightgbm
copying lightgbm/__init__.py -> build/lib/lightgbm
copying lightgbm/engine.py -> build/lib/lightgbm
copying lightgbm/dask.py -> build/lib/lightgbm
copying lightgbm/basic.py -> build/lib/lightgbm
copying lightgbm/libpath.py -> build/lib/lightgbm
copying lightgbm/sklearn.py -> build/lib/lightgbm
running egg_info
creating lightgbm.egg-info
writing lightgbm.egg-info/PKG-INFO
writing dependency_links to lightgbm.egg-info/dependency_links.txt
writing requirements to lightgbm.egg-info/requires.txt
writing top-level names to lightgbm.egg-info/top_level.txt
writing manifest file 'lightgbm.egg-info/SOURCES.txt'
reading manifest file 'lightgbm.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
no previously-included directories found matching 'build'
warning: no files found matching 'LICENSE'
warning: no files found matching '*.txt'
warning: no files found matching '*.so' under directory 'lightgbm'
warning: no files found matching 'compile/CMakeLists.txt'
warning: no files found matching 'compile/cmake/IntegratedOpenCL.cmake'
warning: no files found matching '*.so' under directory 'compile'
warning: no files found matching '*.dll' under directory 'compile/Release'
warning: no files found matching 'compile/external_libs/compute/CMakeLists.txt'
warning: no files found matching '*' under directory 'compile/external_libs/compute/cmake'
warning: no files found matching '*' under directory 'compile/external_libs/compute/include'
warning: no files found matching '*' under directory 'compile/external_libs/compute/meta'
warning: no files found matching 'compile/external_libs/eigen/CMakeLists.txt'
warning: no files found matching 'compile/external_libs/eigen/Eigen/Cholesky'
warning: no files found matching 'compile/external_libs/eigen/Eigen/Core'
warning: no files found matching 'compile/external_libs/eigen/Eigen/Dense'
warning: no files found matching 'compile/external_libs/eigen/Eigen/Eigenvalues'
warning: no files found matching 'compile/external_libs/eigen/Eigen/Geometry'
warning: no files found matching 'compile/external_libs/eigen/Eigen/Householder'
warning: no files found matching 'compile/external_libs/eigen/Eigen/Jacobi'
warning: no files found matching 'compile/external_libs/eigen/Eigen/LU'
warning: no files found matching 'compile/external_libs/eigen/Eigen/QR'
warning: no files found matching 'compile/external_libs/eigen/Eigen/SVD'
warning: no files found matching '*' under directory 'compile/external_libs/eigen/Eigen/src/Cholesky'
warning: no files found matching '*' under directory 'compile/external_libs/eigen/Eigen/src/Core'
warning: no files found matching '*' under directory 'compile/external_libs/eigen/Eigen/src/Eigenvalues'
warning: no files found matching '*' under directory 'compile/external_libs/eigen/Eigen/src/Geometry'
warning: no files found matching '*' under directory 'compile/external_libs/eigen/Eigen/src/Householder'
warning: no files found matching '*' under directory 'compile/external_libs/eigen/Eigen/src/Jacobi'
warning: no files found matching '*' under directory 'compile/external_libs/eigen/Eigen/src/LU'
warning: no files found matching '*' under directory 'compile/external_libs/eigen/Eigen/src/misc'
warning: no files found matching '*' under directory 'compile/external_libs/eigen/Eigen/src/plugins'
warning: no files found matching '*' under directory 'compile/external_libs/eigen/Eigen/src/QR'
warning: no files found matching '*' under directory 'compile/external_libs/eigen/Eigen/src/SVD'
warning: no files found matching 'compile/external_libs/fast_double_parser/CMakeLists.txt'
warning: no files found matching 'compile/external_libs/fast_double_parser/LICENSE'
warning: no files found matching 'compile/external_libs/fast_double_parser/LICENSE.BSL'
warning: no files found matching '*' under directory 'compile/external_libs/fast_double_parser/include'
warning: no files found matching 'compile/external_libs/fmt/CMakeLists.txt'
warning: no files found matching 'compile/external_libs/fmt/LICENSE.rst'
warning: no files found matching '*' under directory 'compile/external_libs/fmt/include'
warning: no files found matching '*' under directory 'compile/include'
warning: no files found matching '*' under directory 'compile/src'
warning: no files found matching 'LightGBM.sln' under directory 'compile/windows'
warning: no files found matching 'LightGBM.vcxproj' under directory 'compile/windows'
warning: no files found matching '*.dll' under directory 'compile/windows/x64/DLL'
warning: no previously-included files matching '*.py[co]' found anywhere in distribution
warning: no previously-included files found matching 'compile/external_libs/compute/.git'
writing manifest file 'lightgbm.egg-info/SOURCES.txt'
copying lightgbm/VERSION.txt -> build/lib/lightgbm
running install_lib
creating /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/lightgbm
copying build/lib/lightgbm/callback.py -> /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/lightgbm
copying build/lib/lightgbm/compat.py -> /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/lightgbm
copying build/lib/lightgbm/plotting.py -> /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/lightgbm
copying build/lib/lightgbm/__init__.py -> /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/lightgbm
copying build/lib/lightgbm/engine.py -> /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/lightgbm
copying build/lib/lightgbm/dask.py -> /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/lightgbm
copying build/lib/lightgbm/basic.py -> /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/lightgbm
copying build/lib/lightgbm/libpath.py -> /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/lightgbm
copying build/lib/lightgbm/sklearn.py -> /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/lightgbm
copying build/lib/lightgbm/VERSION.txt -> /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/lightgbm
INFO:LightGBM:Installing lib_lightgbm from: ['/Users/leonidalekseev/LightGBM/lib_lightgbm.so']
copying /Users/leonidalekseev/LightGBM/lib_lightgbm.so -> /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/lightgbm
byte-compiling /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/lightgbm/callback.py to callback.cpython-39.pyc
byte-compiling /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/lightgbm/compat.py to compat.cpython-39.pyc
byte-compiling /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/lightgbm/plotting.py to plotting.cpython-39.pyc
byte-compiling /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/lightgbm/__init__.py to __init__.cpython-39.pyc
byte-compiling /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/lightgbm/engine.py to engine.cpython-39.pyc
byte-compiling /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/lightgbm/dask.py to dask.cpython-39.pyc
byte-compiling /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/lightgbm/basic.py to basic.cpython-39.pyc
byte-compiling /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/lightgbm/libpath.py to libpath.cpython-39.pyc
byte-compiling /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/lightgbm/sklearn.py to sklearn.cpython-39.pyc
running install_egg_info
Copying lightgbm.egg-info to /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/lightgbm-3.3.2.99-py3.9.egg-info
running install_scripts

(base) leonidalekseev@MacBook-Air-Leonid python-package % python
Python 3.9.6 | packaged by conda-forge | (default, Jul 11 2021, 03:35:11)
[Clang 11.1.0 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import lightgbm as lgb
>>> import numpy as np
>>> X = np.random.random((50, 10))
>>> y = np.random.random(50)
>>> lgb.LGBMRegressor().fit(X, y)
[LightGBM] [Warning] Auto-choosing col-wise multi-threading, the overhead of testing was 0.000235 seconds.
You can set `force_col_wise=true` to remove the overhead.
[LightGBM] [Info] Total Bins 180
[LightGBM] [Info] Number of data points in the train set: 50, number of used features: 10
[LightGBM] [Info] Start training from score 0.486477
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
LGBMRegressor()

As I suggested earlier in this thread, miniforge arm64 version was used to run this experiment.

leonidalekseev@MacBook-Air-Leonid ~ % conda info

     active environment : None
            shell level : 0
       user config file : /Users/leonidalekseev/.condarc
 populated config files : /opt/homebrew/Caskroom/miniforge/base/.condarc
                          /Users/leonidalekseev/.condarc
          conda version : 4.10.3
    conda-build version : not installed
         python version : 3.9.6.final.0
       virtual packages : __osx=12.0.1=0
                          __unix=0=0
                          __archspec=1=arm64
       base environment : /opt/homebrew/Caskroom/miniforge/base  (writable)
      conda av data dir : /opt/homebrew/Caskroom/miniforge/base/etc/conda
  conda av metadata url : None
           channel URLs : https://conda.anaconda.org/conda-forge/osx-arm64
                          https://conda.anaconda.org/conda-forge/noarch
          package cache : /opt/homebrew/Caskroom/miniforge/base/pkgs
                          /Users/leonidalekseev/.conda/pkgs
       envs directories : /opt/homebrew/Caskroom/miniforge/base/envs
                          /Users/leonidalekseev/.conda/envs
               platform : osx-arm64
             user-agent : conda/4.10.3 requests/2.26.0 CPython/3.9.6 Darwin/21.1.0 OSX/12.0.1
                UID:GID : 501:20
             netrc file : None
           offline mode : False

I strongly believe that @thvasilo is right and this is

a common problem with other Python packages and M1 Macs

and we can’t do anything with it. Probably this affects Python 3.9 version only.

Some random examples:

@thvasilo Also, raw logs may help. Please install LightGBM in the following way:

brew install cmake
brew install libomp
git clone --recursive https://github.com/microsoft/LightGBM
cd LightGBM
mkdir build
cd build
cmake ..
make -j4

according to https://lightgbm.readthedocs.io/en/latest/Installation-Guide.html#build-from-github and after that run

cd ../python-package
python setup.py install --precompile

I did exactly this and it worked seemlessly for me on my m1 pro 14 inch macbook.

Adding that there is now a formal item on GitHub’s public roadmap for GitHub actions, tracking support for using M1 Macs in GitHub-hosted runners: https://github.com/github/roadmap/issues/528

I think that the runners for macos-latest still use Intel processors. I believe the job you’ve linked using cibuildwheel is using cross-compilation, not truly compiling on + testing on an M1 Mac with an ARM chip.

https://github.com/PyWavelets/pywt/blob/cb1b02bee48e8414d26a9db73cbf3921109e60e4/.github/workflows/wheel_tests_and_release.yml#L131

CIBW_ARCHS_MACOS: x86_64 arm64 universal2

From https://cibuildwheel.readthedocs.io/en/stable/options/#archs

CIBW_ARCHS Change the architectures built on your machine by default. A list of architectures to build. On macOS, this option can be used to cross-compile between x86_64, universal2 and arm64 for Apple Silicon support

The jobs there look super useful, so thanks again for sharing them! But ideally we’d like to test building from source on an actual Mac with an ARM chip.

That’s why we’re closely watching https://github.com/actions/virtual-environments/issues/2187.

And I found another discussion tonight where GitHub indicated that they’re actively working on adding an ARM MacOS runner image: https://github.com/actions/runner/issues/805#issuecomment-1041968059.

what about using cibuildwheel?

Maybe! We have a separate discussion going on in #5061 about possibly changing the toolchain for how this project builds wheels.

But the most important thing we need to be able to provide a wheel for the M1 Mac is a free CI resource, not different build tooling. Without that, it won’t be possible to guarantee the changes to the codebase don’t break compatibility with the M1 Macs.

I strongly believe that the root cause here is Python and LightGBM architectures mismatch.

So I think that maybe this is additional evidence that LightGBM’s C/C++ source code isn’t inherently incompatible with the M1 Macs, and that changes to its CMake configuration (as @StrikerRUS suggested) might be required.

Another evidence that LightGBM works fine on M1 is Homebrew: they build some bottles on macOS ARM64 machines:

CPU: octa-core 64-bit arm_firestorm_icestorm
Clang: 13.0.0 build 1300
Git: 2.30.1 => /usr/bin/git
Curl: 7.77.0 => /usr/bin/curl
macOS: 12.0.1-arm64
CLT: 13.1.0.0.1.1633545042
Xcode: 13.1
Rosetta 2: false

https://github.com/Homebrew/homebrew-core/runs/4740548221?check_suite_focus=true

And in contrast to CRAN compilation, Homebrew builds LightGBM with CMake via the following commands: https://github.com/Homebrew/homebrew-core/blob/c34e36ed9feb170d4b10ed72d5bb4cb6f83d2a5f/Formula/lightgbm.rb#L22-L26 https://github.com/Homebrew/brew/blob/069ab087f99fd183aee599bf785cb835d5868407/Library/Homebrew/formula.rb#L1514-L1533

According to this, I think that some changes might be needed in some particular environments, but they are not required by default.

I wish I could provide any better help here, but unfortunately I have no access to ordinary, not to mention M1, macOS machine… 🙁