We have a Python monorepo managed via Pants. A rec...
# general
d
We have a Python monorepo managed via Pants. A recent feature request resulted in us trying to add lightgbm as a dependency to one of our Python projects. This is causing problems for folks who are using the repo on m1 / m2 macbooks, but works fine for Linux users. It looks like Pants / PEX is trying to build the wheel from source instead of using a binary distribution. The lightgbm docs mention that running
brew install libomp
is likely required. I've done that, but it's not making the error go away. I'll put the full error in the thread. Lightgbm version: 4.3.0 Repo Python version: 3.9.5 Application resolve Python: 3.10.12 Pants version: 2.18.0 (but also happens in 2.19.0) Any ideas on what's going on here and how we can resolve it?
1
Copy code
× Building wheel for lightgbm (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [41 lines of output]
      2024-03-04 09:38:48,863 - scikit_build_core - INFO - RUN: /Users/stephenhopper/.cache/pants/named_caches/pex_root/pip/23.1.2/pip_cache/.tmp/pip-build-env-31sagpts/normal/lib/python3.10/site-packages/cmake/data/bin/cmake --version
      2024-03-04 09:38:48,871 - scikit_build_core - INFO - CMake version: 3.28.3
      *** scikit-build-core 0.8.2 using CMake 3.28.3 (wheel)
      2024-03-04 09:38:48,877 - scikit_build_core - INFO - Build directory: /Users/stephenhopper/.cache/pants/named_caches/pex_root/pip/23.1.2/pip_cache/.tmp/tmpd5h2myww/build
      *** Configuring CMake...
      2024-03-04 09:38:48,893 - scikit_build_core - INFO - RUN: /Users/stephenhopper/.cache/pants/named_caches/pex_root/pip/23.1.2/pip_cache/.tmp/pip-build-env-31sagpts/normal/lib/python3.10/site-packages/ninja/data/bin/ninja --version
      2024-03-04 09:38:48,958 - scikit_build_core - INFO - Ninja version: 1.11.1
      2024-03-04 09:38:48,960 - scikit_build_core - INFO - RUN: /Users/stephenhopper/.cache/pants/named_caches/pex_root/pip/23.1.2/pip_cache/.tmp/pip-build-env-31sagpts/normal/lib/python3.10/site-packages/cmake/data/bin/cmake -S. -B/Users/stephenhopper/.cache/pants/named_caches/pex_root/pip/23.1.2/pip_cache/.tmp/tmpd5h2myww/build -DCMAKE_BUILD_TYPE:STRING=Release -C/Users/stephenhopper/.cache/pants/named_caches/pex_root/pip/23.1.2/pip_cache/.tmp/tmpd5h2myww/build/CMakeInit.txt -DCMAKE_MAKE_PROGRAM=/Users/stephenhopper/.cache/pants/named_caches/pex_root/pip/23.1.2/pip_cache/.tmp/pip-build-env-31sagpts/normal/lib/python3.10/site-packages/ninja/data/bin/ninja -D__BUILD_FOR_PYTHON:BOOL=ON
      loading initial cache file /Users/stephenhopper/.cache/pants/named_caches/pex_root/pip/23.1.2/pip_cache/.tmp/tmpd5h2myww/build/CMakeInit.txt
      -- The C compiler identification is AppleClang 14.0.3.14030022
      -- The CXX compiler identification is AppleClang 14.0.3.14030022
      -- 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
      -- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES)
      -- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES)
      -- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND)
      Error: $HOME must be set to run brew.
      -- Found OpenMP_C: -Xpreprocessor -fopenmp -I/include
      -- Found OpenMP_CXX: -Xpreprocessor -fopenmp -I/include
      -- Found OpenMP: TRUE
      -- Performing Test MM_PREFETCH
      -- Performing Test MM_PREFETCH - Failed
      -- Performing Test MM_MALLOC
      -- Performing Test MM_MALLOC - Success
      -- Using _mm_malloc
      -- Configuring done (1.2s)
      -- Generating done (0.0s)
      -- Build files have been written to: /Users/stephenhopper/.cache/pants/named_caches/pex_root/pip/23.1.2/pip_cache/.tmp/tmpd5h2myww/build
      *** Building project with Ninja...
      2024-03-04 09:38:50,226 - scikit_build_core - INFO - RUN: /Users/stephenhopper/.cache/pants/named_caches/pex_root/pip/23.1.2/pip_cache/.tmp/pip-build-env-31sagpts/normal/lib/python3.10/site-packages/cmake/data/bin/cmake --build /Users/stephenhopper/.cache/pants/named_caches/pex_root/pip/23.1.2/pip_cache/.tmp/tmpd5h2myww/build
      ninja: error: '/lib/libomp.dylib', needed by '/Users/stephenhopper/.cache/pants/named_caches/pex_root/pip/23.1.2/pip_cache/.tmp/pip-req-build-_ihaga_j/lib_lightgbm.so', missing and no known rule to make it

      *** CMake build failed
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for lightgbm
ERROR: Failed to build one or more wheels
h
AFAICT there are no published wheels for macos arm64: https://pypi.org/project/lightgbm/#files
So building from the sdist seems like the only thing pex (or pip for that matter) can do
d
Oh fun. Given that I've run
brew install libomp
, how do I pipe that through so that Pants / PEX can see it?
c
Regarding the PEX side, this issue seems relevant: https://github.com/pex-tool/pex/issues/2097
h
I'm not sure about that. Sounds like they do want lightgbm in the pex, but cannot build it because the underlying pip build is not seeing libomp, despite it being installed via brew.
So now the debugging begins: first try and reproduce in standalone pip. If that works, try and reproduce in standalone pex.
d
Building with pip works. I'll try building with standalone pex next.
h
So it may be some env vars needing to be plumbed through
pip has full access to the env, whereas Pants sandboxes things. But you can poke holes in that via https://www.pantsbuild.org/2.19/reference/subsystems/subprocess-environment#env_vars
d
Looking at the log, the $HOME variable is missing in the sandboxed environment, so the CMake cannot find the brew-installed openmp (there is some logic for that - https://github.com/microsoft/LightGBM/blob/b27d81ea411d04d8d071d4d4e75c19ffa15c5795/CMakeLists.txt#L154).
h
You can poke a hole for $HOME in the env vars as described at that link
d
If I override in the
pants.toml
, should I include the default values too?
Passing
HOME
through to the subprocess fixed the error. Thank you so much!
🎉 1