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
I strongly believe that @thvasilo is right and this is
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:
according to https://lightgbm.readthedocs.io/en/latest/Installation-Guide.html#build-from-github and after that run
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!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.
For
brewcommands logs are unavailable unfortunately.As I suggested earlier in this thread, miniforge arm64 version was used to run this experiment.
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-lateststill use Intel processors. I believe the job you’ve linked usingcibuildwheelis 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
From https://cibuildwheel.readthedocs.io/en/stable/options/#archs
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.
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.
Another evidence that LightGBM works fine on M1 is Homebrew: they build some bottles on macOS ARM64 machines:
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… 🙁