Xgboost: Error while import xgboost in Python (OSError symbol not found)

Created on 8 Mar 2018  路  5Comments  路  Source: dmlc/xgboost

Environment info

Operating System:
Alpine 3.7

Compiler:

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-alpine-linux-musl/6.4.0/lto-wrapper
Target: x86_64-alpine-linux-musl
Configured with: /home/buildozer/aports/main/gcc/src/gcc-6.4.0/configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --build=x86_64-alpine-linux-musl --host=x86_64-alpine-linux-musl --target=x86_64-alpine-linux-musl --with-pkgversion='Alpine 6.4.0' --enable-checking=release --disable-fixed-point --disable-libstdcxx-pch --disable-multilib --disable-nls --disable-werror --disable-symvers --enable-__cxa_atexit --enable-default-pie --enable-cloog-backend --enable-languages=c,c++,objc,java,fortran,ada --disable-libssp --disable-libmpx --disable-libmudflap --disable-libsanitizer --enable-shared --enable-threads --enable-tls --with-system-zlib --with-linker-hash-style=gnu
Thread model: posix
gcc version 6.4.0 (Alpine 6.4.0)
  1. The python version and distribution
3.6.4 (default, Mar  2 2018, 16:14:31) 
[GCC 6.4.0]
  1. The command to install xgboost if you are not installing from source
    pip install xgboost

Steps to reproduce

  1. Install xgboost in Alpine Linux using pip
  2. import xgboost

Error stacktrace:

OSErrorTraceback (most recent call last)
<ipython-input-7-9a75a239d539> in <module>()
----> 1 import xgboost
      2 print(xgboost.__version__)

/usr/lib/python3.6/site-packages/xgboost/__init__.py in <module>()
      9 import os
     10 
---> 11 from .core import DMatrix, Booster
     12 from .training import train, cv
     13 from . import rabit                   # noqa

/usr/lib/python3.6/site-packages/xgboost/core.py in <module>()
    113 
    114 # load the XGBoost library globally
--> 115 _LIB = _load_lib()
    116 
    117 

/usr/lib/python3.6/site-packages/xgboost/core.py in _load_lib()
    107     if len(lib_path) == 0:
    108         return None
--> 109     lib = ctypes.cdll.LoadLibrary(lib_path[0])
    110     lib.XGBGetLastError.restype = ctypes.c_char_p
    111     return lib

/usr/lib/python3.6/ctypes/__init__.py in LoadLibrary(self, name)
    424 
    425     def LoadLibrary(self, name):
--> 426         return self._dlltype(name)
    427 
    428 cdll = LibraryLoader(CDLL)

/usr/lib/python3.6/ctypes/__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error)
    346 
    347         if handle is None:
--> 348             self._handle = _dlopen(self._name, mode)
    349         else:
    350             self._handle = handle

OSError: Error relocating /usr/lib/python3.6/site-packages/xgboost/./lib/libxgboost.so: backtrace: symbol not found

Most helpful comment

Seems like I found a solution of this problem
Solution not mine but I spend a lot of time to find workaround
And finally I found this Dockerfile, modify it for my purposes and it works!

All 5 comments

You may have a better luck with

pip3 install xgboost==0.7.post4

If not, we suggest that you compile from the sources on GitHub.

Thanks @hcho3, but unfortunately didn't worked too, I got the same error:

>>> import xgboost
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.6/site-packages/xgboost/__init__.py", line 11, in <module>
    from .core import DMatrix, Booster
  File "/usr/lib/python3.6/site-packages/xgboost/core.py", line 115, in <module>
    _LIB = _load_lib()
  File "/usr/lib/python3.6/site-packages/xgboost/core.py", line 109, in _load_lib
    lib = ctypes.cdll.LoadLibrary(lib_path[0])
  File "/usr/lib/python3.6/ctypes/__init__.py", line 426, in LoadLibrary
    return self._dlltype(name)
  File "/usr/lib/python3.6/ctypes/__init__.py", line 348, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: Error relocating /usr/lib/python3.6/site-packages/xgboost/./lib/libxgboost.so: backtrace: symbol not found

I already tried install from source but got a different error. I'll try again and post here.

Based on my searches in issues, I guess that this error is happening due the gcc version., but I'm not sure.

Hi!
Have same problem with Python 2.7.14 and gcc version 6.3.0 on Alpine 3.6

Seems like I found a solution of this problem
Solution not mine but I spend a lot of time to find workaround
And finally I found this Dockerfile, modify it for my purposes and it works!

Thanks @chinskiy! It's solved my problem, I have a working project here.

Was this page helpful?
0 / 5 - 0 ratings