scikit-learn: Scikit-learn can not be built with OpenMP support

Description

I got this error while compiling the source code of scikit-learn on my Mac. I have been follow the introduction step by step given by Advanced installation instructions. But still have the following error:

Any help will be appreciated

Steps/Code to Reproduce

sudo python setup.py install

Expected Results

Complie and install successfully

Actual Results

Partial import of sklearn during the build process.

/Users/sundaycat/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/distutils/dist.py:274: UserWarning: Unknown distribution option: 'project_urls'
  warnings.warn(msg)
/Users/sundaycat/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/distutils/dist.py:274: UserWarning: Unknown distribution option: 'python_requires'
  warnings.warn(msg)
/Users/sundaycat/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/distutils/dist.py:274: UserWarning: Unknown distribution option: 'install_requires'
  warnings.warn(msg)
C compiler: gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/sundaycat/.pyenv/versions/anaconda3-5.3.1/include -arch x86_64 -I/Users/sundaycat/.pyenv/versions/anaconda3-5.3.1/include -arch x86_64

compile options: '-c'
extra options: '-fopenmp'
gcc: test_openmp.c
clang: error: unsupported option '-fopenmp'
clang: error: unsupported option '-fopenmp'
Traceback (most recent call last):
  File "setup.py", line 290, in <module>
    setup_package()
  File "setup.py", line 286, in setup_package
    setup(**metadata)
  File "/Users/sundaycat/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/site-packages/numpy/distutils/core.py", line 135, in setup
    config = configuration()
  File "setup.py", line 174, in configuration
    config.add_subpackage('sklearn')
  File "/Users/sundaycat/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/site-packages/numpy/distutils/misc_util.py", line 1034, in add_subpackage
    caller_level = 2)
  File "/Users/sundaycat/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/site-packages/numpy/distutils/misc_util.py", line 1003, in get_subpackage
    caller_level = caller_level + 1)
  File "/Users/sundaycat/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/site-packages/numpy/distutils/misc_util.py", line 940, in _get_configuration_from_setup_py
    config = setup_module.configuration(*args)
  File "sklearn/setup.py", line 76, in configuration
    maybe_cythonize_extensions(top_path, config)
  File "/Users/sundaycat/Dev/scikit-learn/sklearn/_build_utils/__init__.py", line 43, in maybe_cythonize_extensions
    with_openmp = check_openmp_support()
  File "/Users/sundaycat/Dev/scikit-learn/sklearn/_build_utils/openmp_helpers.py", line 140, in check_openmp_support
    raise CompileError(err_message)
distutils.errors.CompileError:
                    ***

It seems that scikit-learn cannot be built with OpenMP support.

- Make sure you have followed the installation instructions:

    https://scikit-learn.org/dev/developers/advanced_installation.html

- If your compiler supports OpenMP but the build still fails, please
  submit a bug report at:

    https://github.com/scikit-learn/scikit-learn/issues

- If you want to build scikit-learn without OpenMP support, you can set
  the environment variable SKLEARN_NO_OPENMP and rerun the build
  command. Note however that some estimators will run in sequential
  mode and their `n_jobs` parameter will have no effect anymore.

Versions

scikit-learn: lastest version python: 3.7 Numpy: 1.15.1 SciPy: 1.1.0 Joblib: 0.13.2

Platform: MacOS 10.14.6

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 2
  • Comments: 46 (25 by maintainers)

Most upvoted comments

Hi, I try to follow the instructions: (https://scikit-learn.org/dev/developers/advanced_installation.html#macos)

Screenshot 2019-11-09 at 9 10 03 PM

I already installed the macOS command line tools using: xcode-select --install

and

I installed the LLVM OpenMP library using: brew install libomp

How do I can do the next step?

export CC=/usr/bin/clang
export CXX=/usr/bin/clang++
export CPPFLAGS="$CPPFLAGS -Xpreprocessor -fopenmp"
export CFLAGS="$CFLAGS -I/usr/local/opt/libomp/include"
export CXXFLAGS="$CXXFLAGS -I/usr/local/opt/libomp/include"
export LDFLAGS="$LDFLAGS -Wl,-rpath,/usr/local/opt/libomp/lib -L/usr/local/opt/libomp/lib -lomp"

This fixed the issue. I tried the second option to install libomp with Homebrew. It worked like a charm. Thanks for your help!

@AlexanderZatserkovnyy Would you mind opening a separate issue somewhere maybe at >https://bugs.gentoo.org/ and cc me, as your issue is fairly a different problem form the OP. Thanks!

!!! Have found the reference to https://github.com/stefantalpalaru/gentoo-overlay/blob/master/sci-libs/scikits_learn/scikits_learn-0.21.3.ebuild in https://bugs.gentoo.org/675212 .

It assembles scikits_learn-0.21.3 for me without the problem with openmp. I’m not sure what the root of the problem (non-zero exit status 139) with updated 0.19.ebuild, but it’s not important. Thanks!

Hi, I try to follow the instructions: (https://scikit-learn.org/dev/developers/advanced_installation.html#macos)

Screenshot 2019-11-09 at 9 10 03 PM

I already installed the macOS command line tools using: xcode-select --install

and

I installed the LLVM OpenMP library using: brew install libomp

How do I can do the next step?

export CC=/usr/bin/clang
export CXX=/usr/bin/clang++
export CPPFLAGS="$CPPFLAGS -Xpreprocessor -fopenmp"
export CFLAGS="$CFLAGS -I/usr/local/opt/libomp/include"
export CXXFLAGS="$CXXFLAGS -I/usr/local/opt/libomp/include"
export LDFLAGS="$LDFLAGS -Wl,-rpath,/usr/local/opt/libomp/lib -L/usr/local/opt/libomp/lib -lomp"

In terminal, type: nano ~/.bash_profile Copy paste to it and Crtl+X save it.

@AlexanderZatserkovnyy Would you mind opening a separate issue somewhere maybe at https://bugs.gentoo.org/ and cc me, as your issue is fairly a different problem form the OP. Thanks!

What about raising a warning in sklearn init if the build has been done without openmp support ?