microsoft/LightGBM

[python-package] Cannot install LightGBM

Killpit opened this issue · 4 comments

Description

I am trying to install LightGBM but whenever I try to install it, I get this error

Reproducible example

pip install lightgbm
Collecting lightgbm
  Using cached lightgbm-4.0.0.tar.gz (1.7 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: scipy in ./venv/lib/python3.10/site-packages (from lightgbm) (1.11.1)
Requirement already satisfied: numpy in ./venv/lib/python3.10/site-packages (from lightgbm) (1.25.2)
Building wheels for collected packages: lightgbm
  Building wheel for lightgbm (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Building wheel for lightgbm (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [45 lines of output]
      2023-08-13 14:36:12,145 - scikit_build_core - INFO - CMake version: 3.27.2
      *** scikit-build-core 0.4.8 using CMake 3.27.2 (wheel)
      2023-08-13 14:36:12,150 - scikit_build_core - INFO - Build directory: /private/var/folders/y4/jnpd1pl92r50hk6sfmrcq20c0000gn/T/tmpn528t095/build
      *** Configuring CMake...
      2023-08-13 14:36:12,590 - scikit_build_core - INFO - Ninja version: 1.11.1
      2023-08-13 14:36:12,591 - scikit_build_core - WARNING - libdir/ldlibrary: /Library/Frameworks/Python.framework/Versions/3.10/lib/Python.framework/Versions/3.10/Python is not a real file!
      loading initial cache file /var/folders/y4/jnpd1pl92r50hk6sfmrcq20c0000gn/T/tmpn528t095/build/CMakeInit.txt
      CMake Deprecation Warning at CMakeLists.txt:35 (cmake_minimum_required):
        Compatibility with CMake < 3.5 will be removed from a future version of
        CMake.
      
        Update the VERSION argument <min> value or use a ...<max> suffix to tell
        CMake that the project does not need compatibility with older versions.
      
      
      -- 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: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/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: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/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)
      -- Found OpenMP_C: -Xpreprocessor -fopenmp -I/opt/homebrew/opt/libomp/include
      -- Found OpenMP_CXX: -Xpreprocessor -fopenmp -I/opt/homebrew/opt/libomp/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 (2.1s)
      -- Generating done (0.0s)
      -- Build files have been written to: /var/folders/y4/jnpd1pl92r50hk6sfmrcq20c0000gn/T/tmpn528t095/build
      *** Building project with Ninja...
      ninja: error: '/opt/homebrew/opt/libomp/lib/libomp.dylib', needed by '/private/var/folders/y4/jnpd1pl92r50hk6sfmrcq20c0000gn/T/pip-install-nj8eih_s/lightgbm_fbb81935721e47e2b01bf4ab5b7285c7/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
Failed to build lightgbm
ERROR: Could not build wheels for lightgbm, which is required to install pyproject.toml-based projects

[notice] A new release of pip available: 22.3.1 -> 23.2.1
[notice] To update, run: pip install --upgrade pip
You have new mail in /var/mail/atatekeli
(venv) atatekeli:customer-prediction-with-deployment atatekeli$ 

Environment info

LightGBM version or commit hash:

I used PyCharm's library installation and then I tried installing with the pip command. Also, I tried to install 3.3.2 version instead of the latest version

Thanks for using LightGBM.

LightGBM expects by default to find OpenMP installed locally, and to be able to dynamically link to it. It appears from this line that you don't have it installed.

ninja: error: '/opt/homebrew/opt/libomp/lib/libomp.dylib', needed by '/private/var/folders/y4/jnpd1pl92r50hk6sfmrcq20c0000gn/T/pip-install-nj8eih_s/lightgbm_fbb81935721e47e2b01bf4ab5b7285c7/lib_lightgbm.so', missing and no known rule to make it

Since it appears from the logs you provided that you're on a Mac, you can install it like this:

brew install libomp

Alternatively, if you don't want to use OpenMP, you can install a version of lightgbm that does not use OpenMP. Training and prediction will be slower (as a result of not using multithreading), but you'll be able to build lightgbm.

If you absolutely have to stay on lightgbm v3.3.2, run the following

pip install 'pip<23.1'
pip install \
    --no-binary lightgbm \
    --install-option='--nomp' \
    'lightgbm==3.3.2'

The pip ceiling is because pip v23.1 removed support for --install-option: #5061 (comment).

If you can upgrade to lightgbm v4.0.0, please do. It contains almost 2 years of performance enhancements, bugfixes, and new features relative to v3.3.2. With that version, you can install a no-OpenMP version like this:

pip install --upgrade pip
pip install \
   --no-binary lightgbm \
   --config-settings=cmake.define.USE_OPENMP=OFF \
   'lightgbm>=4.0.0'

Many of these details, and others about installation of the Python package, are available at https://github.com/microsoft/LightGBM/blob/master/python-package/README.rst.

Also note... I've edited your post to make the difference between text you wrote, commands you ran, and logs from those commands clearer.

Please see https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax for information on how to format text on GitHub.

Thanks, I finally installed LightGBM, also I'll look at the guide before I write a problem.

This issue has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.