Ann
Ann

Reputation: 241

XGBoostLibraryNotFound: Cannot find XGBoost Library in the candidate path, did you install compilers and run build.sh in root path?

I am facing this problem while moving the python-package directory of XGBoost.

Traceback (most recent call last): File "setup.py", line 19, in LIB_PATH = libpath'find_lib_path' File "xgboost/libpath.py", line 46, in find_lib_path 'List of candidates:\n' + ('\n'.join(dll_path))) builtin.XGBoostLibraryNotFound: Cannot find XGBoost Library in the candidate path, did you install compilers and run build.sh in root path?

Could anyone explain to me how to fix it? thanks in advance.

Upvotes: 24

Views: 32712

Answers (10)

Bak_was
Bak_was

Reputation: 45

1.I started off with the conda installation from anaconda prompt:

(base) C:\Users\abhi.b>conda install -c anaconda py-xgboost

This lead to the following error :

Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: \
Found conflicts! Looking for incompatible packages.
This can take several minutes.  Press CTRL-C to abort.|
failed

UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:

Specifications:

  - py-xgboost -> python[version='>=2.7,<2.8.0a0|>=3.6,<3.7.0a0|>=3.7,<3.8.0a0|>=3.5,<3.6.0a0']

Your python: python=3.8

If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.

Decided not to followup this path, as exploring python downgrade was not an option for me.

2.There after i followed "The final attempt that works " on the below link : https://medium.com/analytics-vidhya/this-is-what-you-should-do-if-you-fail-to-install-the-latest-or-an-older-version-of-xgboost-on-7942a7641eee

However i got the same error as other users faced ::

>>> import xgboost as xgb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\__init__.py", line 11, in <module>
  from .core import DMatrix, Booster
File "C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\core.py", line 161, in <module>
  _LIB = _load_lib()
File "C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\core.py", line 123, in _load_lib
  lib_paths = find_lib_path()
File "C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\libpath.py", line 45, in find_lib_path
  raise XGBoostLibraryNotFound(
xgboost.libpath.XGBoostLibraryNotFound: Cannot find XGBoost Library in the candidate path, did you install compilers and run build.sh in root path?
List of candidates:
C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\xgboost.dll
C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\../../lib/xgboost.dll
C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\./lib/xgboost.dll
C:\Users\abhi.b\Anaconda3\xgboost\xgboost.dll
C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\../../windows/x64/Release/xgboost.dll
C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\./windows/x64/Release/xgboost.dll
>>> exit() 

BTW the link to download xgboost.dll as posted above - https://picnet.com.au/blog/xgboost-windows-x64-binaries-for-download/ was not clear to me ,so i decided to not follow this thread.

3.Finally ,the solution was very simple for me,Open ANACONDA PROMPT and Type

(base) C:\Users\abhi.b>pip install xgboost

This lead to

Collecting xgboost
  Downloading xgboost-1.2.1-py3-none-win_amd64.whl (86.5 MB)
     |████████████████████████████████| 86.5 MB 1.7 MB/s
Requirement already satisfied: scipy in c:\users\abhi.b\anaconda3\lib\site-packages (from xgboost) (1.5.0)
Requirement already satisfied: numpy in c:\users\abhi.b\anaconda3\lib\site-packages (from xgboost) (1.18.5)
Installing collected packages: xgboost
Successfully installed xgboost-1.2.1

Then goto python prompt

(base) C:\Users\abhi.b>python
>>>import xgboost as xgb

Or you can type the same command on IDE ie Spyder etc Voila!!

Upvotes: 0

Saurabh Singhai
Saurabh Singhai

Reputation: 318

  1. Search for xgboost.dll file under your C:\Users<your-user-name> directory. If you have installed xgboost, somewhere you should find a copy of the xgboost.dll file.

  2. Once you find the xgboost.dll file, just copy it to one of the paths mentioned in the error message, e.g. C:\Users<your-user-name>\AppData\Roaming\Python\Python37\site-packages\xgboost\ . Import should work now.

Upvotes: 0

Shradha
Shradha

Reputation: 2452

I faced the same error while installing xgboost using anaconda prompt because the installation of xgboost was interfering with the versions of some other pre-installed libraries. Installing xgboost by creating a virtual environment solved the issue.

On macOS and Linux:

python3 -m pip install --user virtualenv #Install virtualenv module
python3 -m venv env #Create a virtual environment 'env'
source env/bin/activate #Activate virtual environment
pip install xgboost #Install xgboost

On Windows:

py -m pip install --user virtualenv #Install virtualenv module
py -m venv env #Create a virtual environment 'env'
.\env\Scripts\activate #Activate virtual environment
pip install xgboost #Install xgboost

Refer https://packaging.python.org/guides/installing-using-pip-and-virtual-environments for help regarding virtual environment.

Upvotes: 0

Syed Taha
Syed Taha

Reputation: 31

Try this it worked for me:

brew install gcc-5
brew install cmake
pip install xgboost

Upvotes: 2

Naganandini S
Naganandini S

Reputation: 1

I had the same issues. I downloaded the file (xgboost.dll) from (https://picnet.com.au/blog/xgboost-windows-x64-binaries-for-download/) into the already existing xgboost folder (C:\Users\Naganandini\AppData\Roaming\Python\Python37\site-packages\xgboost). It's perfectly working now :)

Upvotes: 0

mirekphd
mirekphd

Reputation: 6831

In my case (Ubuntu 16.04, with CUDA 9.0) the Python library build was evidently broken by adding R library package to the cmake options list:

1) python lib installation works OK:

cmake .. -DUSE_CUDA=ON -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-${CUDA_VER} 
cd /tmp/xgboost/python-package && python3 setup.py install

2) adding '-DR_LIB=ON' switch to cmake breaks subsequent python library installation attempt:

cmake .. -DUSE_CUDA=ON -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-${CUDA_VER} -DR_LIB=ON 
cd /tmp/xgboost/python-package && python3 setup.py install

> "XGBoostLibraryNotFound: Cannot find XGBoost Library in the candidate path, did you install compilers and run build.sh in root
> path?"

Upvotes: 0

Patrick Stetz
Patrick Stetz

Reputation: 495

The other answers didn't work for me so I installed xgboost through Conda commands as listed here.

Just run conda install -c conda-forge xgboost

Upvotes: 8

Ehsan Mehralian
Ehsan Mehralian

Reputation: 345

thanks to Joe Nyland that found the a good answer for this problem in here.
As he said (and also worked for me) you need to run following commands:

 $ brew install gcc@5
 $ pip install xgboost

Upvotes: 4

user2723494
user2723494

Reputation: 1228

The first answer's suggestions did not work for me, and left me with the same error as the original question.

If I'm assuming correctly that your full error message is something like this:

C:\Users\Matt\xgboost\python-package>python setup.py install
Traceback (most recent call last):
  File "setup.py", line 19, in <module>
    LIB_PATH = [os.path.relpath(libfile, CURRENT_DIR) for libfile in libpath['find_lib_path']()]
  File "xgboost/libpath.py", line 49, in find_lib_path
    'List of candidates:\n' + ('\n'.join(dll_path)))
XGBoostLibraryNotFound: Cannot find XGBoost Library in the candidate path, did you install compilers and run build.sh in root path?
List of candidates:
C:\Users\Matt\xgboost\python-package\xgboost\xgboost.dll
C:\Users\Matt\xgboost\python-package\xgboost\../../lib/xgboost.dll
C:\Users\Matt\xgboost\python-package\xgboost\./lib/xgboost.dll
C:\Users\Matt\AppData\Local\Programs\Python\Python35\xgboost\xgboost.dll
C:\Users\Matt\xgboost\python-package\xgboost\../../windows/x64/Release/xgboost.dll
C:\Users\Matt\xgboost\python-package\xgboost\./windows/x64/Release/xgboost.dll

then the solution is to

1) Get/find/download the library that setup.py is looking for. Search the xgboost folder for .dll files. See if you can find something like xgboost.dll it might be called libxgboost.dll. If you can, move to step 2. If you cannot find it download it here

2) Copy the .dll file into the xgboost/python-package/xgboost folder. If that .dll is not called xgboost.dll (i.e. if it's called libxgboost.dll) then change the name to xgboost.dll

3) Run the commands as outlined in Gustavo answer. Note these are meant to be run from Git Bash.

If you want a more soup-to-nuts tutorial, this was the best one I found.

Upvotes: 7

Gustavo
Gustavo

Reputation: 189

You get that message when trying to install the xgboost Python package without the xgboost binaries present. The proper way to install the xgboost Python package from source is the following (assuming you have a compiler such as gcc installed):

git clone --recursive https://github.com/dmlc/xgboost.git
cd xgboost
./build.sh
cd python-package
python setup.py install

I prefer to do it inside a virtual environment. Note that the option --recursive when cloning the repo is essential since it will also clone folders from different repos such as dmlc-core which are necessary for building xgboost.

Upvotes: 18

Related Questions